From 057f80ddfc69c7a0d773a0fbe6c482e63bd8816b Mon Sep 17 00:00:00 2001 From: Olaf van der Spek Date: Sun, 29 May 2016 18:47:32 +0200 Subject: [PATCH 1/3] Update Windows files --- src/windows/ctemplate/find_ptr.h | 9 +++++++++ src/windows/ctemplate/template.h | 8 ++------ src/windows/ctemplate/template_annotator.h | 1 - src/windows/ctemplate/template_dictionary.h | 5 ----- src/windows/ctemplate/template_dictionary_interface.h | 1 - src/windows/ctemplate/template_emitter.h | 1 - src/windows/ctemplate/template_enums.h | 1 - src/windows/ctemplate/template_modifiers.h | 4 +--- src/windows/ctemplate/template_namelist.h | 1 - src/windows/ctemplate/template_string.h | 3 +-- 10 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/windows/ctemplate/find_ptr.h b/src/windows/ctemplate/find_ptr.h index 8e6fec5..8e50e78 100644 --- a/src/windows/ctemplate/find_ptr.h +++ b/src/windows/ctemplate/find_ptr.h @@ -33,6 +33,8 @@ #ifndef TEMPLATE_FIND_PTR_H_ #define TEMPLATE_FIND_PTR_H_ +#include + // NOTE: if you are statically linking the template library into your binary // (rather than using the template .dll), set '/D CTEMPLATE_DLL_DECL=' // as a compiler flag in your project file to turn off the dllimports. @@ -42,6 +44,13 @@ namespace ctemplate { +template +const typename T::value_type* find_ptr0(const T& c, U v) +{ + typename T::const_iterator i = c.find(v); + return i == c.end() ? NULL : &*i; +} + template typename T::value_type::second_type* find_ptr(T& c, U v) { diff --git a/src/windows/ctemplate/template.h b/src/windows/ctemplate/template.h index 4d12cb7..403c322 100644 --- a/src/windows/ctemplate/template.h +++ b/src/windows/ctemplate/template.h @@ -57,7 +57,7 @@ class PerExpandData; } #endif -namespace google_ctemplate_streamhtmlparser { +namespace ctemplate_htmlparser { class HtmlParser; } @@ -324,9 +324,6 @@ class CTEMPLATE_DLL_DECL Template { static bool StringToTemplateCache(const TemplateString& key, const char* content, Strip); - // INSTEAD, use ReloadAllIfChanged. - bool ReloadIfChanged(); - protected: friend class SectionTemplateNode; // for access to set_state(), ParseState friend class TemplateTemplateNode; // for recursive call to Expand() @@ -439,7 +436,7 @@ class CTEMPLATE_DLL_DECL Template { TemplateContext initial_context_; // Non-null if the template was initialized in an Auto-Escape mode that // requires a parser (currently TC_HTML, TC_CSS and TC_JS). - google_ctemplate_streamhtmlparser::HtmlParser *htmlparser_; + ctemplate_htmlparser::HtmlParser *htmlparser_; // A sorted list of trusted variable names, declared here because a unittest // needs to verify that it is appropriately sorted (an unsorted array would @@ -488,5 +485,4 @@ class CTEMPLATE_DLL_DECL Template { } - #endif // CTEMPLATE_TEMPLATE_H_ diff --git a/src/windows/ctemplate/template_annotator.h b/src/windows/ctemplate/template_annotator.h index e7daf6d..e43a880 100644 --- a/src/windows/ctemplate/template_annotator.h +++ b/src/windows/ctemplate/template_annotator.h @@ -138,5 +138,4 @@ class CTEMPLATE_DLL_DECL TextTemplateAnnotator : public TemplateAnnotator { } - #endif // TEMPLATE_TEMPLATE_ANNOTATOR_H_ diff --git a/src/windows/ctemplate/template_dictionary.h b/src/windows/ctemplate/template_dictionary.h index c1f3869..a4a062e 100644 --- a/src/windows/ctemplate/template_dictionary.h +++ b/src/windows/ctemplate/template_dictionary.h @@ -236,10 +236,6 @@ class CTEMPLATE_DLL_DECL TemplateDictionary : public TemplateDictionaryInterface __attribute__((__format__ (__printf__, 4, 5))) #endif ; // starts at 4 because of implicit 1st arg 'this' - void SetEscapedValueAndShowSection(const TemplateString variable, - const TemplateString value, - const TemplateModifier& escfn, - const TemplateString section_name); private: @@ -460,5 +456,4 @@ class CTEMPLATE_DLL_DECL TemplateDictionary : public TemplateDictionaryInterface } - #endif // TEMPLATE_TEMPLATE_DICTIONARY_H_ diff --git a/src/windows/ctemplate/template_dictionary_interface.h b/src/windows/ctemplate/template_dictionary_interface.h index 03bae41..93ae4b1 100644 --- a/src/windows/ctemplate/template_dictionary_interface.h +++ b/src/windows/ctemplate/template_dictionary_interface.h @@ -145,5 +145,4 @@ class CTEMPLATE_DLL_DECL TemplateDictionaryInterface { } - #endif // TEMPLATE_TEMPLATE_DICTIONARY_INTERFACE_H_ diff --git a/src/windows/ctemplate/template_emitter.h b/src/windows/ctemplate/template_emitter.h index 58d038a..f6e9f41 100644 --- a/src/windows/ctemplate/template_emitter.h +++ b/src/windows/ctemplate/template_emitter.h @@ -72,5 +72,4 @@ class CTEMPLATE_DLL_DECL StringEmitter : public ExpandEmitter { } - #endif // TEMPLATE_TEMPLATE_EMITTER_H_ diff --git a/src/windows/ctemplate/template_enums.h b/src/windows/ctemplate/template_enums.h index a240e75..57db6ca 100644 --- a/src/windows/ctemplate/template_enums.h +++ b/src/windows/ctemplate/template_enums.h @@ -43,5 +43,4 @@ enum Strip { DO_NOT_STRIP, STRIP_BLANK_LINES, STRIP_WHITESPACE, } - #endif // TEMPLATE_TEMPLATE_ENUMS_H_ diff --git a/src/windows/ctemplate/template_modifiers.h b/src/windows/ctemplate/template_modifiers.h index b981a60..41d6a81 100644 --- a/src/windows/ctemplate/template_modifiers.h +++ b/src/windows/ctemplate/template_modifiers.h @@ -348,10 +348,8 @@ bool AddModifier(const char* long_name, const TemplateModifier* modifier); // is used in a different context (say Javascript) where this // escaping may be inadequate. extern CTEMPLATE_DLL_DECL -bool AddXssSafeModifier(const char* long_name, - const TemplateModifier* modifier); +bool AddXssSafeModifier(const char* long_name, const TemplateModifier* modifier); } - #endif // TEMPLATE_TEMPLATE_MODIFIERS_H_ diff --git a/src/windows/ctemplate/template_namelist.h b/src/windows/ctemplate/template_namelist.h index 26bd03a..da36a1f 100644 --- a/src/windows/ctemplate/template_namelist.h +++ b/src/windows/ctemplate/template_namelist.h @@ -165,5 +165,4 @@ class CTEMPLATE_DLL_DECL TemplateNamelist { } - #endif // TEMPLATE_TEMPLATE_NAMELIST_H_ diff --git a/src/windows/ctemplate/template_string.h b/src/windows/ctemplate/template_string.h index f1bd38b..bcc226b 100644 --- a/src/windows/ctemplate/template_string.h +++ b/src/windows/ctemplate/template_string.h @@ -342,7 +342,7 @@ class CTEMPLATE_DLL_DECL StaticTemplateStringInitializer { // Don't use this. This is used only in auto-generated .varnames.h files. #define STS_INIT_WITH_HASH(name, str, hash_compare) \ - { { str, sizeof(""str"")-1, hash_compare } }; \ + { { str, sizeof("" str "")-1, hash_compare } }; \ namespace ctemplate_sts_init { \ static const ctemplate::StaticTemplateStringInitializer name##_init(&name); \ } @@ -359,5 +359,4 @@ const StaticTemplateString kStsEmpty = } - #endif // TEMPLATE_TEMPLATE_STRING_H_ From d17dd5d192cd755bbe01bc299d3c5592146887ef Mon Sep 17 00:00:00 2001 From: Olaf van der Spek Date: Sun, 29 May 2016 21:22:39 +0200 Subject: [PATCH 2/3] Use std::unordered_map --- src/windows/config.h | 6 +++--- src/windows/ctemplate/per_expand_data.h | 6 +++--- src/windows/ctemplate/template_cache.h | 6 +++--- src/windows/ctemplate/template_namelist.h | 4 ++-- src/windows/ctemplate/template_string.h | 4 ++-- src/windows/preprocess.sh | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/windows/config.h b/src/windows/config.h index d8a1e94..0cf6411 100644 --- a/src/windows/config.h +++ b/src/windows/config.h @@ -19,13 +19,13 @@ #define GOOGLE_NAMESPACE ctemplate /* the location of or */ -#define HASH_MAP_H +#define HASH_MAP_H /* the namespace of hash_map/hash_set */ -#define HASH_NAMESPACE stdext +#define HASH_NAMESPACE std /* the location of or */ -#define HASH_SET_H +#define HASH_SET_H /* Define to 1 if you have the header file. */ #undef HAVE_BYTESWAP_H diff --git a/src/windows/ctemplate/per_expand_data.h b/src/windows/ctemplate/per_expand_data.h index 6abce97..62d3622 100644 --- a/src/windows/ctemplate/per_expand_data.h +++ b/src/windows/ctemplate/per_expand_data.h @@ -45,7 +45,7 @@ #include // for NULL #include // for strcmp #include -#include +#include #include // for StringHash // NOTE: if you are statically linking the template library into your binary @@ -131,12 +131,12 @@ class CTEMPLATE_DLL_DECL PerExpandData { private: #ifdef _MSC_VER - typedef stdext::hash_map DataMap; + typedef std::unordered_map DataMap; #else struct DataEq { bool operator()(const char* s1, const char* s2) const; }; - typedef stdext::hash_map + typedef std::unordered_map DataMap; #endif diff --git a/src/windows/ctemplate/template_cache.h b/src/windows/ctemplate/template_cache.h index 2ee6b67..70c3c7a 100644 --- a/src/windows/ctemplate/template_cache.h +++ b/src/windows/ctemplate/template_cache.h @@ -34,7 +34,7 @@ #ifndef TEMPLATE_TEMPLATE_CACHE_H_ #define TEMPLATE_TEMPLATE_CACHE_H_ -#include // for stdext::hash_map<> +#include // for std::unordered_map<> #include // for string #include // for pair #include // for vector<> @@ -288,9 +288,9 @@ class CTEMPLATE_DLL_DECL TemplateCache { public: typedef std::pair TemplateCacheKey; private: - typedef stdext::hash_map + typedef std::unordered_map TemplateMap; - typedef stdext::hash_map TemplateCallMap; + typedef std::unordered_map TemplateCallMap; // Where to search for files. typedef std::vector TemplateSearchPath; diff --git a/src/windows/ctemplate/template_namelist.h b/src/windows/ctemplate/template_namelist.h index da36a1f..df6ab0e 100644 --- a/src/windows/ctemplate/template_namelist.h +++ b/src/windows/ctemplate/template_namelist.h @@ -40,7 +40,7 @@ #define TEMPLATE_TEMPLATE_NAMELIST_H_ #include // for time_t -#include +#include #include #include #include // for Strip @@ -87,7 +87,7 @@ class CTEMPLATE_DLL_DECL TemplateNamelist { // thing you should do with them is call size() and/or iterate // between begin() and end(), and the only operations we promise // the iterators will support are operator* and operator++. - typedef stdext::hash_set NameListType; + typedef std::unordered_set NameListType; typedef std::vector MissingListType; typedef std::vector SyntaxListType; diff --git a/src/windows/ctemplate/template_string.h b/src/windows/ctemplate/template_string.h index bcc226b..3c6aded 100644 --- a/src/windows/ctemplate/template_string.h +++ b/src/windows/ctemplate/template_string.h @@ -34,7 +34,7 @@ #define TEMPLATE_TEMPLATE_STRING_H_ #include // for memcmp() and size_t -#include +#include #include #include @@ -142,7 +142,7 @@ struct CTEMPLATE_DLL_DECL StaticTemplateString { } do_not_use_directly_; // This class is a good hash_compare functor to pass in as the third - // argument to stdext::hash_map<>, when creating a map whose keys are + // argument to std::unordered_map<>, when creating a map whose keys are // StaticTemplateString. NOTE: This class isn't that safe to use, // because it requires that StaticTemplateStringInitializer has done // its job. Unfortunately, even when you use the STS_INIT macro diff --git a/src/windows/preprocess.sh b/src/windows/preprocess.sh index b089180..b6ed5ba 100755 --- a/src/windows/preprocess.sh +++ b/src/windows/preprocess.sh @@ -99,8 +99,8 @@ template class __declspec(dllexport) std::vector;\n\ -e "s!@ac_windows_dllexport_defines@!$MY_DLLDEF_DEFINES!g" \ -e "s!@ac_cv_cxx_hash_map@!$HASH_MAP_H!g" \ -e "s!@ac_cv_cxx_hash_set@!$HASH_SET_H!g" \ - -e "s!@ac_cv_cxx_hash_map_class@!$HASH_NAMESPACE::hash_map!g" \ - -e "s!@ac_cv_cxx_hash_set_class@!$HASH_NAMESPACE::hash_set!g" \ + -e "s!@ac_cv_cxx_hash_map_class@!$HASH_NAMESPACE::unordered_map!g" \ + -e "s!@ac_cv_cxx_hash_set_class@!$HASH_NAMESPACE::unordered_set!g" \ -e "s!@ac_google_attribute@!${HAVE___ATTRIBUTE__:-0}!g" \ -e "s!@ac_google_end_namespace@!$_END_GOOGLE_NAMESPACE_!g" \ -e "s!@ac_google_namespace@!$GOOGLE_NAMESPACE!g" \ From 01a5302032fa1ca250692ccb944782bc5e7fe02a Mon Sep 17 00:00:00 2001 From: Jan Stilow Date: Wed, 1 Jun 2016 16:23:00 +0200 Subject: [PATCH 3/3] Fix to build with python2 by default I used python2.7 first, however after looking through issue #104 and the python2.patch I switched using python2 instead because python2 seems to be more generic. --- src/htmlparser/generate_fsm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/htmlparser/generate_fsm.py b/src/htmlparser/generate_fsm.py index 9106b96..3f1e535 100755 --- a/src/htmlparser/generate_fsm.py +++ b/src/htmlparser/generate_fsm.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 # # Copyright (c) 2008, Google Inc. # All rights reserved.