MaxMind-DB-Writer-0.300003000755000000000000 013321164704 14131 5ustar00rootroot000000000000Changes100644000000000000 2162613321164704 15534 0ustar00rootroot000000000000MaxMind-DB-Writer-0.3000030.300003 2018-07-10 [ BUG FIXES ] - Fixed compilation errors. GitHub #96. 0.300002 2018-06-06 [ BUG FIXES ] - You can now freeze a tree where the data section size in memory is more than 2,147,479,552 bytes. GitHub #94. 0.300001 2018-03-08 - This package now builds on Windows. Pull request by Ilya Melamed. GitHub #91. 0.300000 2017-11-10 - The remove_reserved_networks option now sets up the tree in such a way that these networks may not be added. Previously these networks could be added and were removed when writing out the tree. This change means these networks are excluded when working with the tree prior to writing it out, such as when iterating the in-memory tree. 0.202000 2016-12-19 - The data insertion code was significantly refactored in order to improve performance on inserts that result in record merges. 0.201004 2016-12-07 [ BUG FIXES ] - In an IPv6 tree with aliasing enabled, the IPv4 root node is now fixed, meaning that it cannot be merged away or replaced. Previously, it was possible for this node to be freed, causing aliases to be invalid. 0.201003 2016-11-30 [ BUG FIXES ] - The previous release included many unneeded modules in the configure phase prereqs. 0.201002 2016-11-30 [ ENHANCEMENTS ] - Data merges are now cached so that we do not have to merge the same two hashes repeatedly. - Remove unnecessary encode call that slowed down generation of data key on inserts. 0.201001 2016-07-13 [ BUG FIXES ] - The writer now throws an exception if you try to insert a network that contains an alias node. Previously, the alias node would be overwritten. 0.201000 2016-04-22 [ ENHANCEMENTS ] - The insertion methods now take a merge_strategy argument. - An add-only-if-parent-exists merge strategy was added. This replaces the functionality of insert_only_if_parent_exists. [ OTHER ] - Deprecated insert_only_if_parent_exists and force_overwrite insertion arguments. These arguments will now warn and will be removed in a future major release. - Deprecated merge_record_collisions constructor argument. This argument will now warn and will be removed in a future major release. 0.200004 2016-04-20 [ ENHANCEMENTS ] - Added the optional tree insertion argument insert_only_if_parent_exists. When enabled, data will be inserted if a record already exists for the network and only if the parent hash reference already exists. This argument can only be used when the merge_strategy is "recurse". 0.200003 2016-04-11 [ BACKWARDS INCOMPATIBILITIES ] - The Teredo range is no longer removed from the database when "remove_reserved_networks" is enabled. This range is globally routable and aliased to the IPv4 range when "alias_ipv6_to_ipv4" is enabled. Previously this alias would be removed if both "alias_ipv6_to_ipv4" and "remove_reserved_networks" were enabled. [ ENHANCEMENTS ] - Allow changing the record size when unfreezing a frozen tree 0.200002 2016-04-07 [ BACKWARDS INCOMPATIBILITIES ] - The in-memory tree now has a root record rather than a root node. This fixes the insertion of a /0 network (GitHub #55) and a segmentation fault when merging two /1 networks into a /0 network (GitHub #58). Although insertions of /0 are allowed (e.g., to create a default record for the database), writing, iterating, and freezing a database that only contains a single /0 data record are currently forbidden. [ BUG FIXES ] - Fixed a bug where an incorrect node_count could be written to the database, causing invalid metadata errors when reading it. [ OTHER ] - The node_count() method on the Tree object now always recalculates the node count rather than using a possibly incorrect cached value. 0.200001 2016-04-04 [ BACKWARDS INCOMPATIBILITIES ] - Inserts into IPv4 aliased subtrees are no longer allowed when alias_ipv6_to_ipv4 is enabled. When using an aliased tree, you will only be able to insert IPv4 networks into ::0.0.0.0/96. If you are inserting these addresses using IPv4 notation, not IPv6, this is the default location and the change will not affect you. The reason for this is that inserting into the aliased subnets leads to complications in determining the correct tree depth for the insert and could also cause unintentional overwriting of data. [ BUG FIXES ] - Some memory leaks when throwing an exception were fixed. 0.200000 2016-03-31 [ BACKWARDS INCOMPATIBILITIES ] - When calling $tree->write_tree(), this module now defaults to removing reserved and private networks from the tree before writing the tree to the filehandle. If you want to create a tree that contains private networks, set the constructor parameter "remove_reserved_networks" to false. This change of behavior was done to allow code that previously used Net::Works::Network->range_as_subnets() to use the new insert_range() method added in this release. - When recursively merging a subtree, alias nodes are no longer followed. Although this is a behavior change, it should not affect most users are previously aliasing was done when the tree was written. [ ENHANCEMENTS ] - This module no longer used Net::Works internally. This was done to improve performance. - Added MaxMind::DB::Writer::Tree->insert_range() method to provide a mechanism for adding IP address ranges that are not well-defined networks. - Added MaxMind::DB::Writer::Tree->remove_network() to allow for removing a network from a tree. [ BUG FIXES ] - Previously, inserting IPv6-mapped IPv4 addresses into a IPv6 tree with IPv4 aliasing enabled could result in a corrupt search tree unless the deprecated "::a.b.c.d" mapping was used. This happened because the IPv4 aliasing was only done after all of the data had been inserted. 0.100007 2016-03-24 - MaxMind::DB::Writer::Tree->new now accepts a merge_strategy parameter. When merge_record_collisions is set, the default merge strategy is "toplevel", which only merges the top level of the record hash. A new "recurse" merge strategy has been added, which recursively merged the records data structure, including both arrays and hashes. Please see the documentation for more details. 0.100006 2016-01-18 - The documentation incorrectly stated the the MaxMind::DB::Writer::Tree->new parameter "map_key_type_callback" was optional. It is actually required. 0.100005 2015-10-26 - $tree->insert_network now takes an optional additional-arguments hash reference parameter. If this hash contains a truthy value for the force_overwrite key, any data for the network will be overwritten even when merge_record_collisions is enabled. 0.100004 2015-07-15 - Previously two equivalent data structures added to a database could end up with different keys, causing both to be added to the final file separately. The key generation was updated to reduce the likelihood of this happening. 0.100003 2015-06-04 - Fixed a bug in the data thawing code that incorrectly incremented the SV referencing the HV rather than the HV. This could cause warnings about attempts to free an unreferenced SV. - Fixed memory leaks on merge failures. - Minor code cleanups. 0.100002 2015-04-23 - Fixed test suite on OS X: Altered to cope with different Net::Works network rendering on OS X 0.100001 2015-03-12 - Updated to the latest versions of the Math::Int128 (0.21) and Math::Int64 (0.51) C API integration code, as well as depending on the newest version of the module from Perl. 0.080000 2015-03-04 - Implemented $tree->freeze_tree and MaxMind::DB::Writer::Tree->new_from_frozen_tree methods. This provides a way of passing the tree between different processes. - Made the attribute reader methods for all values passed to the constructor public. - Added some docs on how insert order affects overlapping networks. GitHub #18. - Fixed memory leaks when adding data to the tree. - Reduced the size of various structs used in the C code to reduce memory usage. 0.060000 2014-11-11 - The map_key_type_callback argument for the MaxMind::DB::Writer::Tree class is now required. In some use cases it's not really used but in the most common use case leaving it out simply leads to confusing errors when attempting to write the tree to disk. GH #10. 0.050007 2014-10-20 - The writer now iterates over the search tree in depth-first order when the MaxMind::DB::Writer::Tree->iterate method is called. This means that networks are seen in IP address order. 0.050006 2014-07-28 - The writer now throw an error when writing out the database if it would try to write a record value in the search tree that is larger than the search tree can handle. For example, if your record size is 24 bits, you cannot write a value larger than (2^24)-1. Fixed by Greg Oschwald. - The Build.PL file shipped with this distro now dies if you try to run it on Windows, since this module simply doesn't work on Windows. 0.050005 2014-07-03 - The merge-on-collision feature was fairly broken. Fixed by Greg Oschwald. 0.050004 2014-05-27 - First public release LICENSE100644000000000000 4365513321164704 15254 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003This software is copyright (c) 2018 by MaxMind, Inc. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2018 by MaxMind, Inc. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy 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 1, 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2018 by MaxMind, Inc. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End INSTALL100644000000000000 316013321164704 15243 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003This is the Perl distribution MaxMind-DB-Writer. Installing MaxMind-DB-Writer is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm MaxMind::DB::Writer If it does not have permission to install modules to the current perl, cpanm will automatically set up and install to a local::lib in your home directory. See the local::lib documentation (https://metacpan.org/pod/local::lib) for details on enabling it in your environment. ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan MaxMind::DB::Writer ## Manual installation As a last resort, you can manually install it. Download the tarball, untar it, then build it: % perl Build.PL % ./Build && ./Build test Then install it: % ./Build install Or the more portable variation: % perl Build.PL % perl Build % perl Build test % perl Build install If your perl is system-managed, you can create a local::lib in your home directory to install modules to. For details, see the local::lib documentation: https://metacpan.org/pod/local::lib The prerequisites of this distribution will also have to be installed manually. The prerequisites are listed in one of the files: `MYMETA.yml` or `MYMETA.json` generated by running the manual build process described above. ## Documentation MaxMind-DB-Writer documentation is available as POD. You can run `perldoc` from a shell to read the documentation: % perldoc MaxMind::DB::Writer For more information on installing Perl modules via CPAN, please see: https://www.cpan.org/modules/INSTALL.html c000755000000000000 013321164704 14274 5ustar00rootroot000000000000MaxMind-DB-Writer-0.300003tree.c100644000000000000 23257213321164704 15612 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/c#include "tree.h" #ifndef WIN32 #include #else #include "windows_mman.h" #endif #include #include #include #include #include #include #include #include #include #ifdef __GNUC__ #define UNUSED(x) UNUSED_##x __attribute__((__unused__)) #else #define UNUSED(x) UNUSED_##x #endif /* This is also defined in MaxMind::DB::Common but we don't want to have to * fetch it every time we need it. */ #define DATA_SECTION_SEPARATOR_SIZE (16) #define SHA1_KEY_LENGTH (27) #define MERGE_KEY_SIZE (57) typedef struct freeze_args_s { FILE *file; char *filename; HV *data_hash; } freeze_args_s; typedef struct thawed_network_s { MMDBW_network_s *network; MMDBW_record_s *record; } thawed_network_s; typedef struct encode_args_s { PerlIO *output_io; SV *root_data_type; SV *serializer; HV *data_pointer_cache; } encode_args_s; struct network { const char *const ipstr; const uint8_t prefix_length; }; static void verify_ip(MMDBW_tree_s *tree, const char *ipstr); static int128_t ip_string_to_integer(const char *ipstr, int family); static int128_t ip_bytes_to_integer(uint8_t *bytes, int family); static void integer_to_ip_bytes(int tree_ip_version, uint128_t ip, uint8_t *bytes); static void integer_to_ip_string(int tree_ip_version, uint128_t ip, char *dst, int dst_length); static int prefix_length_for_largest_subnet(uint128_t start_ip, uint128_t end_ip, int family, uint128_t *reverse_mask); static const char * store_data_in_tree(MMDBW_tree_s *tree, const char *const key, SV *data_sv); static const char *increment_data_reference_count(MMDBW_tree_s *tree, const char *const key); static void set_stored_data_in_tree(MMDBW_tree_s *tree, const char *const key, SV *data_sv); static void decrement_data_reference_count(MMDBW_tree_s *tree, const char *const key); static MMDBW_network_s resolve_network(MMDBW_tree_s *tree, const char *const ipstr, uint8_t prefix_length); static MMDBW_status resolve_ip(int tree_ip_version, const char *const ipstr, uint8_t *bytes); static void free_network(MMDBW_network_s *network); static void alias_ipv4_networks(MMDBW_tree_s *tree); static MMDBW_status insert_reserved_networks_as_fixed_empty(MMDBW_tree_s *tree); static MMDBW_status insert_networks_as_fixed_empty(MMDBW_tree_s *tree, struct network const *const networks, const size_t num_networks); static MMDBW_status insert_record_for_network(MMDBW_tree_s *tree, MMDBW_network_s *network, MMDBW_record_s *new_record, MMDBW_merge_strategy merge_strategy, bool is_internal_insert); static MMDBW_status insert_record_into_next_node(MMDBW_tree_s *tree, MMDBW_record_s *current_record, MMDBW_network_s *network, int current_bit, MMDBW_record_s *new_record, MMDBW_merge_strategy merge_strategy, bool is_internal_insert); static MMDBW_status insert_record_into_current_record(MMDBW_tree_s *tree, MMDBW_record_s *current_record, MMDBW_network_s *network, MMDBW_record_s *new_record, MMDBW_merge_strategy merge_strategy); static const char *maybe_merge_records(MMDBW_tree_s *tree, MMDBW_network_s *network, MMDBW_record_s *new_record, MMDBW_record_s *record_to_set, MMDBW_merge_strategy merge_strategy); static int network_bit_value(MMDBW_network_s *network, uint8_t current_bit); static int tree_depth0(MMDBW_tree_s *tree); static SV *merge_hashes(MMDBW_tree_s *tree, SV *from, SV *into, MMDBW_merge_strategy merge_strategy); static void merge_new_from_hash_into_hash(MMDBW_tree_s *tree, HV *from, HV *to, MMDBW_merge_strategy merge_strategy); static SV *merge_values(MMDBW_tree_s *tree, SV *from, SV *into, MMDBW_merge_strategy merge_strategy); static SV *merge_arrays(MMDBW_tree_s *tree, SV *from, SV *into, MMDBW_merge_strategy merge_strategy); static MMDBW_status find_record_for_network(MMDBW_tree_s *tree, MMDBW_network_s *network, MMDBW_record_s **record); static MMDBW_node_s *new_node_from_record(MMDBW_tree_s *tree, MMDBW_record_s *record); static MMDBW_status free_node_and_subnodes(MMDBW_tree_s *tree, MMDBW_node_s *node, bool remove_alias_and_fixed_nodes); static MMDBW_status free_record_value(MMDBW_tree_s *tree, MMDBW_record_s *record, bool remove_alias_and_fixed_nodes); static void assign_node_number(MMDBW_tree_s *tree, MMDBW_node_s *node, uint128_t UNUSED(network), uint8_t UNUSED(depth), void *UNUSED(args)); static void freeze_search_tree(MMDBW_tree_s *tree, freeze_args_s *args); static void freeze_node(MMDBW_tree_s *tree, MMDBW_node_s *node, uint128_t network, uint8_t depth, void *void_args); static void freeze_data_record(MMDBW_tree_s *UNUSED(tree), uint128_t network, uint8_t depth, const char *key, freeze_args_s *args); static void freeze_to_file(freeze_args_s *args, void *data, size_t size); static void freeze_data_to_file(freeze_args_s *args, MMDBW_tree_s *tree); static SV *freeze_hash(HV *hash); static uint8_t thaw_uint8(uint8_t **buffer); static thawed_network_s *thaw_network(MMDBW_tree_s *tree, uint8_t **buffer); static uint8_t *thaw_bytes(uint8_t **buffer, size_t size); static uint128_t thaw_uint128(uint8_t **buffer); static STRLEN thaw_strlen(uint8_t **buffer); static const char *thaw_data_key(uint8_t **buffer); static HV *thaw_data_hash(SV *data_to_decode); static void encode_node(MMDBW_tree_s *tree, MMDBW_node_s *node, uint128_t UNUSED(network), uint8_t UNUSED(depth), void *void_args); static void check_record_sanity(MMDBW_node_s *node, MMDBW_record_s *record, char *side); static uint32_t record_value_as_number(MMDBW_tree_s *tree, MMDBW_record_s *record, encode_args_s *args); static void iterate_tree(MMDBW_tree_s *tree, MMDBW_record_s *record, uint128_t network, const uint8_t depth, bool depth_first, void *args, MMDBW_iterator_callback callback); static SV *key_for_data(SV *data); static const char *merge_cache_lookup(MMDBW_tree_s *tree, char *merge_cache_key); static void store_in_merge_cache(MMDBW_tree_s *tree, char *merge_cache_key, const char *const new_key); static void *checked_malloc(size_t size); static void checked_fwrite(FILE *file, char *filename, void *buffer, size_t count); static void check_perlio_result(SSize_t result, SSize_t expected, char *op); static char *status_error_message(MMDBW_status status); static const char *record_type_name(MMDBW_record_type type); // Create a new tree. // // For a description of `alias_ipv6' and `remove_reserved_networks', refer to // the MaxMind::DB::Writer::Tree documentation about these options. MMDBW_tree_s *new_tree(const uint8_t ip_version, uint8_t record_size, MMDBW_merge_strategy merge_strategy, const bool alias_ipv6, const bool remove_reserved_networks) { if (merge_strategy == MMDBW_MERGE_STRATEGY_UNKNOWN) { croak("Unknown merge_strategy encountered"); } if (ip_version != 4 && ip_version != 6) { croak("Unexpected IP version of %u", ip_version); } if (record_size != 24 && record_size != 28 && record_size != 32) { croak("Only record sizes of 24, 28, and 32 are supported. Received %u.", record_size); } MMDBW_tree_s *tree = checked_malloc(sizeof(MMDBW_tree_s)); tree->ip_version = ip_version; tree->record_size = record_size; tree->merge_strategy = merge_strategy; tree->merge_cache = NULL; tree->data_table = NULL; tree->root_record = (MMDBW_record_s){ .type = MMDBW_RECORD_TYPE_EMPTY, }; tree->node_count = 0; if (alias_ipv6) { alias_ipv4_networks(tree); } if (remove_reserved_networks) { MMDBW_status const status = insert_reserved_networks_as_fixed_empty(tree); if (status != MMDBW_SUCCESS) { free_tree(tree); croak("Error inserting reserved networks: %s", status_error_message(status)); } } return tree; } void insert_network(MMDBW_tree_s *tree, const char *ipstr, const uint8_t prefix_length, SV *key_sv, SV *data, MMDBW_merge_strategy merge_strategy) { verify_ip(tree, ipstr); MMDBW_network_s network = resolve_network(tree, ipstr, prefix_length); const char *const key = store_data_in_tree(tree, SvPVbyte_nolen(key_sv), data); MMDBW_record_s new_record = {.type = MMDBW_RECORD_TYPE_DATA, .value = {.key = key}}; MMDBW_status status = insert_record_for_network( tree, &network, &new_record, merge_strategy, false); // The data's ref count gets incremented by the insert each time it is // inserted. As such, we need to decrement it here. decrement_data_reference_count(tree, key); free_network(&network); if (MMDBW_SUCCESS != status) { croak("%s (when inserting %s/%" PRIu8 ")", status_error_message(status), ipstr, prefix_length); } } static void verify_ip(MMDBW_tree_s *tree, const char *ipstr) { if (tree->ip_version == 4 && strchr(ipstr, ':')) { croak("You cannot insert an IPv6 address (%s) into an IPv4 tree.", ipstr); } } void insert_range(MMDBW_tree_s *tree, const char *start_ipstr, const char *end_ipstr, SV *key_sv, SV *data_sv, MMDBW_merge_strategy merge_strategy) { verify_ip(tree, start_ipstr); verify_ip(tree, end_ipstr); uint128_t start_ip = ip_string_to_integer(start_ipstr, tree->ip_version); uint128_t end_ip = ip_string_to_integer(end_ipstr, tree->ip_version); if (end_ip < start_ip) { croak("First IP (%s) in range comes before last IP (%s)", start_ipstr, end_ipstr); } const char *const key = store_data_in_tree(tree, SvPVbyte_nolen(key_sv), data_sv); uint8_t bytes[tree->ip_version == 6 ? 16 : 4]; MMDBW_status status = MMDBW_SUCCESS; // Eventually we could change the code to walk the tree and break up the // range at the same time, saving some unnecessary computation. However, // that would require more significant refactoring of the insertion and // merging code. while (start_ip <= end_ip) { uint128_t reverse_mask; int prefix_length = prefix_length_for_largest_subnet( start_ip, end_ip, tree->ip_version, &reverse_mask); integer_to_ip_bytes(tree->ip_version, start_ip, bytes); MMDBW_network_s network = { .bytes = bytes, .prefix_length = prefix_length, }; MMDBW_record_s new_record = {.type = MMDBW_RECORD_TYPE_DATA, .value = {.key = key}}; status = insert_record_for_network( tree, &network, &new_record, merge_strategy, false); if (MMDBW_SUCCESS != status) { break; } start_ip = (start_ip | reverse_mask) + 1; // The +1 caused an overflow and we are done. if (start_ip == 0) { break; } } // store_data_in_tree starts at a reference count of 1, so we need to // decrement in order to account for that. decrement_data_reference_count(tree, key); if (MMDBW_SUCCESS != status) { croak("%s (when inserting %s - %s)", status_error_message(status), start_ipstr, end_ipstr); } } static int128_t ip_string_to_integer(const char *ipstr, int family) { uint8_t bytes[family == 6 ? 16 : 4]; if (resolve_ip(family, ipstr, bytes) != MMDBW_SUCCESS) { croak("Invalid IP address: %s", ipstr); } return ip_bytes_to_integer(bytes, family); } static int128_t ip_bytes_to_integer(uint8_t *bytes, int family) { int length = family == 6 ? 16 : 4; int128_t ipint = 0; for (int i = 0; i < length; i++) { ipint = (ipint << 8) | bytes[i]; } return ipint; } static void integer_to_ip_bytes(int tree_ip_version, uint128_t ip, uint8_t *bytes) { int bytes_length = tree_ip_version == 6 ? 16 : 4; for (int i = 1; i <= bytes_length; i++) { bytes[bytes_length - i] = 0xFF & ip; ip >>= 8; } } static void integer_to_ip_string(int tree_ip_version, uint128_t ip, char *dst, int dst_length) { uint8_t bytes[tree_ip_version == 6 ? 16 : 4]; integer_to_ip_bytes(tree_ip_version, ip, bytes); if (NULL == inet_ntop(tree_ip_version == 6 ? AF_INET6 : AF_INET, bytes, dst, dst_length)) { croak("Error converting IP integer to string"); } } static int prefix_length_for_largest_subnet(uint128_t start_ip, uint128_t end_ip, int family, uint128_t *reverse_mask) { if (start_ip > end_ip) { croak("Start IP of the range must be less than or equal to end IP"); } int prefix_length = family == 6 ? 128 : 32; *reverse_mask = 1; while ( // First IP of the subnet must be the start IP (start_ip & ~*reverse_mask) == start_ip // the last IP of the subnet must be <= the end IP && (start_ip | *reverse_mask) <= end_ip // stop if we have all IPs (shouldn't be required, but safety measure) && prefix_length > 0) { prefix_length--; *reverse_mask = (*reverse_mask << 1) | 1; } // We overshoot by one shift *reverse_mask >>= 1; return prefix_length; } void remove_network(MMDBW_tree_s *tree, const char *ipstr, const uint8_t prefix_length) { verify_ip(tree, ipstr); MMDBW_network_s network = resolve_network(tree, ipstr, prefix_length); MMDBW_record_s new_record = {.type = MMDBW_RECORD_TYPE_EMPTY}; MMDBW_status status = insert_record_for_network( tree, &network, &new_record, MMDBW_MERGE_STRATEGY_NONE, false); free_network(&network); if (status != MMDBW_SUCCESS) { croak(status_error_message(status)); } } static const char * store_data_in_tree(MMDBW_tree_s *tree, const char *const key, SV *data_sv) { const char *const new_key = increment_data_reference_count(tree, key); set_stored_data_in_tree(tree, key, data_sv); return new_key; } static const char *increment_data_reference_count(MMDBW_tree_s *tree, const char *const key) { MMDBW_data_hash_s *data = NULL; HASH_FIND(hh, tree->data_table, key, SHA1_KEY_LENGTH, data); /* We allow this possibility as we need to create the record separately from updating the data when thawing */ if (NULL == data) { data = checked_malloc(sizeof(MMDBW_data_hash_s)); data->reference_count = 0; data->data_sv = NULL; data->key = checked_malloc(SHA1_KEY_LENGTH + 1); strcpy((char *)data->key, key); HASH_ADD_KEYPTR(hh, tree->data_table, data->key, SHA1_KEY_LENGTH, data); } data->reference_count++; return data->key; } static void set_stored_data_in_tree(MMDBW_tree_s *tree, const char *const key, SV *data_sv) { MMDBW_data_hash_s *data = NULL; HASH_FIND(hh, tree->data_table, key, SHA1_KEY_LENGTH, data); if (NULL == data) { croak("Attempt to set unknown data record in tree"); } if (NULL != data->data_sv) { return; } SvREFCNT_inc_simple_void_NN(data_sv); data->data_sv = data_sv; } static void decrement_data_reference_count(MMDBW_tree_s *tree, const char *const key) { MMDBW_data_hash_s *data = NULL; HASH_FIND(hh, tree->data_table, key, SHA1_KEY_LENGTH, data); if (NULL == data) { croak("Attempt to remove data that does not exist from tree"); } data->reference_count--; if (0 == data->reference_count) { HASH_DEL(tree->data_table, data); SvREFCNT_dec(data->data_sv); free((char *)data->key); free(data); } } static MMDBW_network_s resolve_network(MMDBW_tree_s *tree, const char *const ipstr, uint8_t prefix_length) { uint8_t *bytes = checked_malloc(tree->ip_version == 6 ? 16 : 4); if (resolve_ip(tree->ip_version, ipstr, bytes) != MMDBW_SUCCESS) { free(bytes); croak("Invalid IP address: %s", ipstr); } if (NULL == strchr(ipstr, ':')) { // IPv4 if (prefix_length > 32) { free(bytes); croak("Prefix length greater than 32 on an IPv4 network (%s/%d)", ipstr, prefix_length); } if (tree->ip_version == 6) { // Inserting IPv4 network into an IPv6 tree prefix_length += 96; } } else if (prefix_length > 128) { free(bytes); croak("Prefix length greater than 128 on an IPv6 network (%s/%d)", ipstr, prefix_length); } MMDBW_network_s network = { .bytes = bytes, .prefix_length = prefix_length, }; return network; } static MMDBW_status resolve_ip(int tree_ip_version, const char *const ipstr, uint8_t *bytes) { bool is_ipv4_address = NULL == strchr(ipstr, ':'); int family = is_ipv4_address ? AF_INET : AF_INET6; if (tree_ip_version == 6 && is_ipv4_address) { // We are inserting/looking up an IPv4 address in an IPv6 tree. // The canonical location for this in our database is ::a.b.c.d. // To get this address, we zero out the first 12 bytes of bytes // and then put the IPv4 address in the remaining 4. The reason to // not use getaddrinfo with AI_V4MAPPED is that it gives us // ::FFFF:a.b.c.d and AI_V4MAPPED doesn't work on all platforms. // See GitHub #7 and #51. memset(bytes, 0, 12); bytes += 12; } if (!inet_pton(family, ipstr, bytes)) { return MMDBW_RESOLVING_IP_ERROR; } return MMDBW_SUCCESS; } static void free_network(MMDBW_network_s *network) { free((char *)network->bytes); } static struct network ipv4_aliases[] = { { .ipstr = "::ffff:0:0", .prefix_length = 96, }, {.ipstr = "2001::", .prefix_length = 32}, {.ipstr = "2002::", .prefix_length = 16}}; static void alias_ipv4_networks(MMDBW_tree_s *tree) { if (tree->ip_version == 4) { return; } MMDBW_network_s ipv4_root_network = resolve_network(tree, "::0.0.0.0", 96); MMDBW_node_s *ipv4_root_node = new_node(); MMDBW_record_s ipv4_root_record = { .type = MMDBW_RECORD_TYPE_FIXED_NODE, .value.node = ipv4_root_node, }; MMDBW_status status = insert_record_for_network(tree, &ipv4_root_network, &ipv4_root_record, MMDBW_MERGE_STRATEGY_NONE, true); free_network(&ipv4_root_network); if (status != MMDBW_SUCCESS) { croak("Unable to create IPv4 root node when setting up aliases: %s", status_error_message(status)); } for (size_t i = 0; i < sizeof(ipv4_aliases) / sizeof(struct network); i++) { MMDBW_network_s alias_network = resolve_network( tree, ipv4_aliases[i].ipstr, ipv4_aliases[i].prefix_length); MMDBW_record_s record_for_alias = { .type = MMDBW_RECORD_TYPE_ALIAS, .value.node = ipv4_root_node, }; MMDBW_status status = insert_record_for_network(tree, &alias_network, &record_for_alias, MMDBW_MERGE_STRATEGY_NONE, true); free_network(&alias_network); if (MMDBW_SUCCESS != status) { croak("Unexpected error when searching for last node for alias: %s", status_error_message(status)); } } } // https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml static struct network reserved_networks_ipv4[] = { {.ipstr = "0.0.0.0", .prefix_length = 8}, {.ipstr = "10.0.0.0", .prefix_length = 8}, {.ipstr = "100.64.0.0", .prefix_length = 10}, {.ipstr = "127.0.0.0", .prefix_length = 8}, {.ipstr = "169.254.0.0", .prefix_length = 16}, {.ipstr = "172.16.0.0", .prefix_length = 12}, // This is an odd case. 192.0.0.0/24 is reserved, but there is a note that // says "Not useable unless by virtue of a more specific reservation". As // such, since 192.0.0.0/29 was more recently reserved, it's possible the // intention is that the rest is not reserved any longer. I'm not too clear // on this, but I believe that is the rationale, so I choose to leave it. {.ipstr = "192.0.0.0", .prefix_length = 29}, // TODO(wstorey@maxmind.com): 192.168.0.8/32 // TODO(wstorey@maxmind.com): 192.168.0.9/32 // TODO(wstorey@maxmind.com): 192.168.0.10/32 // TODO(wstorey@maxmind.com): 192.168.0.170/32 // TODO(wstorey@maxmind.com): 192.168.0.171/32 {.ipstr = "192.0.2.0", .prefix_length = 24}, // 192.31.196.0/24 is routable I believe // TODO(wstorey@maxmnd.com): 192.52.193.0/24 // TODO(wstorey@maxmind.com): Looks like 192.88.99.0/24 may no longer be // reserved? {.ipstr = "192.88.99.0", .prefix_length = 24}, {.ipstr = "192.168.0.0", .prefix_length = 16}, // 192.175.48.0/24 is routable I believe {.ipstr = "198.18.0.0", .prefix_length = 15}, {.ipstr = "198.51.100.0", .prefix_length = 24}, {.ipstr = "203.0.113.0", .prefix_length = 24}, // The above IANA page doesn't list 224.0.0.0/4, but at least some parts // are listed in https://tools.ietf.org/html/rfc5771 {.ipstr = "224.0.0.0", .prefix_length = 4}, {.ipstr = "240.0.0.0", .prefix_length = 4}, // 255.255.255.255/32 gets brought in by 240.0.0.0/4. }; // https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml static struct network reserved_networks_ipv6[] = { // ::/128 and ::1/128 are reserved under IPv6 but these are already // covered under 0.0.0.0/8. // // ::ffff:0:0/96 - IPv4 mapped addresses. We treat it specially with the // `alias_ipv6_to_ipv4' option. // // 64:ff9b::/96 - well known prefix mapping, covered by alias_ipv6_to_ipv4 // // TODO(wstorey@maxmind.com): 64:ff9b:1::/48 should be in // alias_ipv6_to_ipv4? {.ipstr = "100::", .prefix_length = 64}, // 2001::/23 is reserved. We include all of it here other than 2001::/32 // as it is Teredo which is globally routable. {.ipstr = "2001:1::", .prefix_length = 32}, {.ipstr = "2001:2::", .prefix_length = 31}, {.ipstr = "2001:4::", .prefix_length = 30}, {.ipstr = "2001:8::", .prefix_length = 29}, {.ipstr = "2001:10::", .prefix_length = 28}, {.ipstr = "2001:20::", .prefix_length = 27}, {.ipstr = "2001:40::", .prefix_length = 26}, {.ipstr = "2001:80::", .prefix_length = 25}, {.ipstr = "2001:100::", .prefix_length = 24}, {.ipstr = "2001:db8::", .prefix_length = 32}, // 2002::/16 - 6to4, part of alias_ipv6_to_ipv4 // 2620:4f:8000::/48 is routable I believe {.ipstr = "fc00::", .prefix_length = 7}, {.ipstr = "fe80::", .prefix_length = 10}, // Multicast {.ipstr = "ff00::", .prefix_length = 8}, }; // Insert a FIXED_EMPTY record for all private and reserved networks. // // This is to avoid the case where we might otherwise accidentally add // information about such networks. static MMDBW_status insert_reserved_networks_as_fixed_empty(MMDBW_tree_s *tree) { MMDBW_status const status = insert_networks_as_fixed_empty( tree, reserved_networks_ipv4, sizeof(reserved_networks_ipv4) / sizeof(struct network)); if (status != MMDBW_SUCCESS) { return status; } if (tree->ip_version == 6) { MMDBW_status const status = insert_networks_as_fixed_empty( tree, reserved_networks_ipv6, sizeof(reserved_networks_ipv6) / sizeof(struct network)); if (status != MMDBW_SUCCESS) { return status; } } return MMDBW_SUCCESS; } // Insert a FIXED_EMPTY record for each network. static MMDBW_status insert_networks_as_fixed_empty(MMDBW_tree_s *tree, struct network const *const networks, const size_t num_networks) { for (size_t i = 0; i < num_networks; i++) { MMDBW_network_s resolved_network = resolve_network(tree, networks[i].ipstr, networks[i].prefix_length); MMDBW_record_s record = { .type = MMDBW_RECORD_TYPE_FIXED_EMPTY, }; MMDBW_status const status = insert_record_for_network( tree, &resolved_network, &record, MMDBW_MERGE_STRATEGY_NONE, true); free_network(&resolved_network); if (status != MMDBW_SUCCESS) { return status; } } return MMDBW_SUCCESS; } static MMDBW_status insert_record_for_network(MMDBW_tree_s *tree, MMDBW_network_s *network, MMDBW_record_s *new_record, MMDBW_merge_strategy merge_strategy, bool is_internal_insert) { if (merge_strategy == MMDBW_MERGE_STRATEGY_UNKNOWN) { merge_strategy = tree->merge_strategy; } return insert_record_into_next_node(tree, &(tree->root_record), network, 0, new_record, merge_strategy, is_internal_insert); } static MMDBW_status insert_record_into_next_node(MMDBW_tree_s *tree, MMDBW_record_s *current_record, MMDBW_network_s *network, int current_bit, MMDBW_record_s *new_record, MMDBW_merge_strategy merge_strategy, bool is_internal_insert) { // We've reached the record where the network belongs. Depending on the // type of record it is, we insert right here. if (current_bit >= network->prefix_length && (current_record->type == MMDBW_RECORD_TYPE_EMPTY || current_record->type == MMDBW_RECORD_TYPE_DATA || (current_record->type == MMDBW_RECORD_TYPE_NODE && merge_strategy == MMDBW_MERGE_STRATEGY_NONE))) { return insert_record_into_current_record( tree, current_record, network, new_record, merge_strategy); } if (current_bit == network->prefix_length && current_record->type == MMDBW_RECORD_TYPE_FIXED_NODE && new_record->type == MMDBW_RECORD_TYPE_FIXED_NODE) { // We could potentially make this work, but it's tricky. One of the // purposes of fixed nodes is for alias nodes to point at them. // Returning success here without doing anything is not what we want to // do: We should be setting the node value to what is in the new record // since it may be setting up alias nodes pointing at it. Changing the // current node value is not an option either: Aliases may already be // pointing to it. // // If we don't have this case, we'll continue to descend the tree, // inserting the new record's fixed node in potentially multiple // locations. If that happens, we end up freeing the node multiple // times when destroying the tree. // // Consider the case where we previously inserted fixed nodes to a // greater depth than we are right now. Because we'd continue to // descend the tree, we'd insert this new fixed node record at // potentially multiple spots in the tree, at each point we encounter // an EMPTY, DATA, or NODE record (the conditions where we can enter // insert_record_into_current_record()). The stopping condition would // not be correct. return MMDBW_FIXED_NODE_OVERWRITE_ATTEMPT_ERROR; } // Figure out the next node. MMDBW_node_s *next_node = NULL; switch (current_record->type) { case MMDBW_RECORD_TYPE_EMPTY: case MMDBW_RECORD_TYPE_DATA: { // In this case we create a new node to point to. We make the new // nodes left and right identical to us. next_node = new_node_from_record(tree, current_record); current_record->value.node = next_node; current_record->type = MMDBW_RECORD_TYPE_NODE; break; } case MMDBW_RECORD_TYPE_FIXED_EMPTY: // We're a) trying to overwrite a fixed empty network, b) trying to // insert a network containing a fixed empty network, or c) trying // to insert inside a fixed empty network. (You can see these 3 // cases handled separately in the ALIAS case.) We ignore the insert // with the assumption that it was not intended. e.g., you probably // didn't mean to insert data about a reserved network. Doing so // makes working with dirty data easier. Note this may change to be // more strict and return an error in the future. return MMDBW_SUCCESS; break; case MMDBW_RECORD_TYPE_ALIAS: { // The insert is trying to overwrite an aliased network. We do not // allow this. if (current_bit == network->prefix_length) { return MMDBW_ALIAS_OVERWRITE_ATTEMPT_ERROR; } // We don't follow aliases when inserting a network that contains // an aliased network within it. if (current_bit > network->prefix_length) { // We return success to silently ignore when we try to insert // here. If we raise an error, it makes working with dirty data // more difficult. We assume such inserts were not intended and // can be safely skipped. return MMDBW_SUCCESS; } // current_bit < network->prefix_length. This means we contain the // new network already as ALIAS. Inserting the network is not valid // because of that. return MMDBW_INSERT_INTO_ALIAS_NODE_ERROR; break; } case MMDBW_RECORD_TYPE_FIXED_NODE: case MMDBW_RECORD_TYPE_NODE: { // We're a node already. next_node = current_record->value.node; break; } } // If we are inserting an alias, a fixed node, or a fixed empty record, we // make all of the nodes down to that record fixed nodes. This makes it // easier to not accidentally delete or modify them. if (new_record->type == MMDBW_RECORD_TYPE_ALIAS || new_record->type == MMDBW_RECORD_TYPE_FIXED_NODE || new_record->type == MMDBW_RECORD_TYPE_FIXED_EMPTY) { current_record->type = MMDBW_RECORD_TYPE_FIXED_NODE; } bool next_is_right = network_bit_value(network, current_bit); // if we are beyond the prefix length, both records are within the // network we are inserting. bool insert_into_both = current_bit >= network->prefix_length; if (next_is_right || insert_into_both) { MMDBW_status status = insert_record_into_next_node(tree, &(next_node->right_record), network, current_bit + 1, new_record, merge_strategy, is_internal_insert); if (status != MMDBW_SUCCESS) { return status; } } if (!next_is_right || insert_into_both) { MMDBW_status status = insert_record_into_next_node(tree, &(next_node->left_record), network, current_bit + 1, new_record, merge_strategy, is_internal_insert); if (status != MMDBW_SUCCESS) { return status; } } // We inserted the new record into the right and/or left record of the next // node. We now need to trim the tree upwards by merging identical records. // Basically what we do here is take care of the case where the record // we're at points at another node, and the records in that node are both // the same. In that case, we delete the node we point at and take its // value on ourselves. if (next_node->left_record.type == next_node->right_record.type && // We don't allow merging into aliases or fixed nodes current_record->type == MMDBW_RECORD_TYPE_NODE) { switch (next_node->left_record.type) { case MMDBW_RECORD_TYPE_EMPTY: { MMDBW_status status = free_node_and_subnodes(tree, next_node, false); if (status != MMDBW_SUCCESS) { return MMDBW_SUCCESS; } current_record->type = MMDBW_RECORD_TYPE_EMPTY; break; } case MMDBW_RECORD_TYPE_DATA: { // If the two keys are the same, the records can be merged. // Otherwise, break. if (strcmp(next_node->left_record.value.key, next_node->right_record.value.key)) { break; } const char *key = increment_data_reference_count( tree, next_node->left_record.value.key); MMDBW_status status = free_node_and_subnodes(tree, next_node, false); if (status != MMDBW_SUCCESS) { return MMDBW_SUCCESS; } current_record->type = MMDBW_RECORD_TYPE_DATA; current_record->value.key = key; break; } case MMDBW_RECORD_TYPE_ALIAS: case MMDBW_RECORD_TYPE_FIXED_NODE: case MMDBW_RECORD_TYPE_FIXED_EMPTY: case MMDBW_RECORD_TYPE_NODE: { // Do nothing in these cases. We don't trim immutable nodes. break; } } } return MMDBW_SUCCESS; } static MMDBW_status insert_record_into_current_record(MMDBW_tree_s *tree, MMDBW_record_s *current_record, MMDBW_network_s *network, MMDBW_record_s *new_record, MMDBW_merge_strategy merge_strategy) { // We only get called when we have a current_record with these record // types. There was previously logic for other types, but that was // confusing. if (current_record->type != MMDBW_RECORD_TYPE_EMPTY && current_record->type != MMDBW_RECORD_TYPE_DATA && current_record->type != MMDBW_RECORD_TYPE_NODE) { return MMDBW_INSERT_INVALID_RECORD_TYPE_ERROR; } if (current_record->type == MMDBW_RECORD_TYPE_EMPTY && merge_strategy == MMDBW_MERGE_STRATEGY_ADD_ONLY_IF_PARENT_EXISTS) { // We do not create a new record when using "only if parent exists" return MMDBW_SUCCESS; } const char *merged_key = maybe_merge_records( tree, network, new_record, current_record, merge_strategy); MMDBW_status status = free_record_value(tree, current_record, false); if (status != MMDBW_SUCCESS) { return status; } // Update the record to match the new one. Replace what's there. current_record->type = new_record->type; if (new_record->type == MMDBW_RECORD_TYPE_DATA) { const char *const key = increment_data_reference_count( tree, merged_key == NULL ? new_record->value.key : merged_key); current_record->value.key = key; } else if (new_record->type == MMDBW_RECORD_TYPE_FIXED_NODE || new_record->type == MMDBW_RECORD_TYPE_NODE || new_record->type == MMDBW_RECORD_TYPE_ALIAS) { current_record->value.node = new_record->value.node; } else if (new_record->type == MMDBW_RECORD_TYPE_EMPTY || new_record->type == MMDBW_RECORD_TYPE_FIXED_EMPTY) { current_record->value.key = NULL; current_record->value.node = NULL; } else { return MMDBW_INSERT_INVALID_RECORD_TYPE_ERROR; } if (merged_key) { decrement_data_reference_count(tree, merged_key); } return status; } static const char *maybe_merge_records(MMDBW_tree_s *tree, MMDBW_network_s *network, MMDBW_record_s *new_record, MMDBW_record_s *record_to_set, MMDBW_merge_strategy merge_strategy) { if (MMDBW_RECORD_TYPE_DATA != new_record->type || merge_strategy == MMDBW_MERGE_STRATEGY_NONE) { return NULL; } /* This must come before the node pruning code in insert_record_for_network, as we only want to prune nodes where the merged record matches. */ if (MMDBW_RECORD_TYPE_DATA != record_to_set->type // If the two keys are equal, there is no point in trying to merge // the contents. || strcmp(new_record->value.key, record_to_set->value.key) == 0) { return NULL; } char merge_cache_key[MERGE_KEY_SIZE + 1]; snprintf(merge_cache_key, MERGE_KEY_SIZE + 1, "%d-%s-%s", merge_strategy, new_record->value.key, record_to_set->value.key); const char *cached_key = merge_cache_lookup(tree, merge_cache_key); if (cached_key != NULL) { const char *const new_key = increment_data_reference_count(tree, cached_key); return new_key; } SV *merged = merge_hashes_for_keys(tree, new_record->value.key, record_to_set->value.key, network, merge_strategy); SV *key_sv = key_for_data(merged); const char *const new_key = store_data_in_tree(tree, SvPVbyte_nolen(key_sv), merged); SvREFCNT_dec(key_sv); /* The ref count was incremented in store_data_in_tree */ SvREFCNT_dec(merged); store_in_merge_cache(tree, merge_cache_key, new_key); return new_key; } static int network_bit_value(MMDBW_network_s *network, uint8_t current_bit) { return network->bytes[current_bit >> 3] & (1U << (~current_bit & 7)); } static int tree_depth0(MMDBW_tree_s *tree) { return tree->ip_version == 6 ? 127 : 31; } SV *merge_hashes_for_keys(MMDBW_tree_s *tree, const char *const key_from, const char *const key_into, MMDBW_network_s *network, MMDBW_merge_strategy merge_strategy) { SV *data_from = data_for_key(tree, key_from); SV *data_into = data_for_key(tree, key_into); if (!(SvROK(data_from) && SvROK(data_into) && SvTYPE(SvRV(data_from)) == SVt_PVHV && SvTYPE(SvRV(data_into)) == SVt_PVHV)) { /* We added key_into earlier during insert_record_for_network, so we have to make sure here that it's removed again after we decide to not actually store this network. It might be nicer to not insert anything into the tree until we're sure we really want to. */ decrement_data_reference_count(tree, key_from); bool is_ipv6 = tree->ip_version == 6; char address_string[is_ipv6 ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN]; inet_ntop(is_ipv6 ? AF_INET6 : AF_INET, network->bytes, address_string, sizeof(address_string)); croak("Cannot merge data records unless both records are hashes - " "inserting %s/%" PRIu8, address_string, network->prefix_length); } return merge_hashes(tree, data_from, data_into, merge_strategy); } static SV *merge_hashes(MMDBW_tree_s *tree, SV *from, SV *into, MMDBW_merge_strategy merge_strategy) { HV *hash_from = (HV *)SvRV(from); HV *hash_into = (HV *)SvRV(into); HV *hash_new = newHV(); merge_new_from_hash_into_hash(tree, hash_into, hash_new, false); merge_new_from_hash_into_hash(tree, hash_from, hash_new, merge_strategy); return newRV_noinc((SV *)hash_new); } // Note: unlike the other merge functions, this does _not_ replace existing // values. static void merge_new_from_hash_into_hash(MMDBW_tree_s *tree, HV *from, HV *to, MMDBW_merge_strategy merge_strategy) { (void)hv_iterinit(from); HE *he; while (NULL != (he = hv_iternext(from))) { STRLEN key_length; const char *const key = HePV(he, key_length); U32 hash = 0; SV *value = HeVAL(he); if (hv_exists(to, key, key_length)) { if (merge_strategy == MMDBW_MERGE_STRATEGY_RECURSE || merge_strategy == MMDBW_MERGE_STRATEGY_ADD_ONLY_IF_PARENT_EXISTS) { SV **existing_value = hv_fetch(to, key, key_length, 0); if (existing_value == NULL) { // This should never happen as we just did an hv_exists croak("Received an unexpected NULL from hv_fetch"); } value = merge_values(tree, value, *existing_value, merge_strategy); } else { // We are replacing the current value hash = HeHASH(he); SvREFCNT_inc_simple_void_NN(value); } } else if (merge_strategy == MMDBW_MERGE_STRATEGY_ADD_ONLY_IF_PARENT_EXISTS && SvROK(value)) { continue; } else { hash = HeHASH(he); SvREFCNT_inc_simple_void_NN(value); } (void)hv_store(to, key, key_length, value, hash); } return; } static SV *merge_values(MMDBW_tree_s *tree, SV *from, SV *into, MMDBW_merge_strategy merge_strategy) { if (SvROK(from) != SvROK(into)) { croak("Attempt to merge a reference value and non-refrence value"); } if (!SvROK(from)) { // If the two values are scalars, we prefer the one in the hash being // inserted. SvREFCNT_inc_simple_void_NN(from); return from; } if (SvTYPE(SvRV(from)) == SVt_PVHV && SvTYPE(SvRV(into)) == SVt_PVHV) { return merge_hashes(tree, from, into, merge_strategy); } if (SvTYPE(SvRV(from)) == SVt_PVAV && SvTYPE(SvRV(into)) == SVt_PVAV) { return merge_arrays(tree, from, into, merge_strategy); } croak("Only arrayrefs, hashrefs, and scalars can be merged."); } static SV *merge_arrays(MMDBW_tree_s *tree, SV *from, SV *into, MMDBW_merge_strategy merge_strategy) { AV *from_array = (AV *)SvRV(from); AV *into_array = (AV *)SvRV(into); // Note that av_len() is really the index of the last element. In newer // Perl versions, it is also called av_top_index() or av_tindex() SSize_t from_top_index = av_len(from_array); SSize_t into_top_index = av_len(into_array); SSize_t new_top_index = from_top_index > into_top_index ? from_top_index : into_top_index; AV *new_array = newAV(); for (SSize_t i = 0; i <= new_top_index; i++) { SV *new_value = NULL; SV **from_value = av_fetch(from_array, i, 0); SV **into_value = av_fetch(into_array, i, 0); if (from_value != NULL && into_value != NULL) { new_value = merge_values(tree, *from_value, *into_value, merge_strategy); } else if (from_value != NULL) { if (merge_strategy == MMDBW_MERGE_STRATEGY_ADD_ONLY_IF_PARENT_EXISTS && SvROK(*from_value)) { break; } new_value = *from_value; SvREFCNT_inc_simple_void_NN(new_value); } else if (into_value != NULL) { new_value = *into_value; SvREFCNT_inc_simple_void_NN(new_value); } else { croak("Received unexpected NULLs when merging arrays"); } av_push(new_array, new_value); } return newRV_noinc((SV *)new_array); } SV *lookup_ip_address(MMDBW_tree_s *tree, const char *const ipstr) { bool is_ipv6_address = NULL != strchr(ipstr, ':'); if (tree->ip_version == 4 && is_ipv6_address) { return &PL_sv_undef; } MMDBW_network_s network = resolve_network(tree, ipstr, is_ipv6_address ? 128 : 32); MMDBW_record_s *record_for_address; MMDBW_status status = find_record_for_network(tree, &network, &record_for_address); free_network(&network); if (MMDBW_SUCCESS != status) { croak("Received an unexpected NULL when looking up %s: %s", ipstr, status_error_message(status)); } if (record_for_address->type == MMDBW_RECORD_TYPE_NODE || record_for_address->type == MMDBW_RECORD_TYPE_FIXED_NODE || record_for_address->type == MMDBW_RECORD_TYPE_ALIAS) { croak("WTF - found a node or alias record for an address lookup - " "%s" PRIu8, ipstr); return &PL_sv_undef; } if (record_for_address->type == MMDBW_RECORD_TYPE_EMPTY || record_for_address->type == MMDBW_RECORD_TYPE_FIXED_EMPTY) { return &PL_sv_undef; } return newSVsv(data_for_key(tree, record_for_address->value.key)); } static MMDBW_status find_record_for_network(MMDBW_tree_s *tree, MMDBW_network_s *network, MMDBW_record_s **record) { *record = &(tree->root_record); for (int current_bit = 0; current_bit < network->prefix_length; current_bit++) { MMDBW_node_s *node; if ((*record)->type == MMDBW_RECORD_TYPE_NODE || (*record)->type == MMDBW_RECORD_TYPE_FIXED_NODE || (*record)->type == MMDBW_RECORD_TYPE_ALIAS) { node = (*record)->value.node; } else { break; } if (network_bit_value(network, current_bit)) { *record = &(node->right_record); } else { *record = &(node->left_record); } } return MMDBW_SUCCESS; } static MMDBW_node_s *new_node_from_record(MMDBW_tree_s *tree, MMDBW_record_s *record) { MMDBW_node_s *node = new_node(); if (record->type == MMDBW_RECORD_TYPE_DATA) { /* We only need to increment the reference count once as we are replacing the parent record */ increment_data_reference_count(tree, record->value.key); node->left_record.type = MMDBW_RECORD_TYPE_DATA; node->left_record.value.key = record->value.key; node->right_record.type = MMDBW_RECORD_TYPE_DATA; node->right_record.value.key = record->value.key; } return node; } MMDBW_node_s *new_node() { MMDBW_node_s *node = checked_malloc(sizeof(MMDBW_node_s)); node->number = 0; node->left_record.type = node->right_record.type = MMDBW_RECORD_TYPE_EMPTY; return node; } static MMDBW_status free_node_and_subnodes(MMDBW_tree_s *tree, MMDBW_node_s *node, bool remove_alias_and_fixed_nodes) { MMDBW_status status = free_record_value( tree, &(node->left_record), remove_alias_and_fixed_nodes); if (status != MMDBW_SUCCESS) { return status; } status = free_record_value( tree, &(node->right_record), remove_alias_and_fixed_nodes); if (status != MMDBW_SUCCESS) { return status; } free(node); return MMDBW_SUCCESS; } static MMDBW_status free_record_value(MMDBW_tree_s *tree, MMDBW_record_s *record, bool remove_alias_and_fixed_nodes) { if (record->type == MMDBW_RECORD_TYPE_FIXED_NODE && !remove_alias_and_fixed_nodes) { return MMDBW_FREED_FIXED_NODE_ERROR; } if (record->type == MMDBW_RECORD_TYPE_FIXED_EMPTY && !remove_alias_and_fixed_nodes) { return MMDBW_FREED_FIXED_EMPTY_ERROR; } if (record->type == MMDBW_RECORD_TYPE_NODE || record->type == MMDBW_RECORD_TYPE_FIXED_NODE) { return free_node_and_subnodes( tree, record->value.node, remove_alias_and_fixed_nodes); } if (record->type == MMDBW_RECORD_TYPE_DATA) { decrement_data_reference_count(tree, record->value.key); } /* Alias nodes should only be removed explicitly. We can't just croak as it will leave the tree in an inconsistent state causing a segfault during unwinding. */ if (record->type == MMDBW_RECORD_TYPE_ALIAS && !remove_alias_and_fixed_nodes) { return MMDBW_FREED_ALIAS_NODE_ERROR; } return MMDBW_SUCCESS; } void assign_node_numbers(MMDBW_tree_s *tree) { tree->node_count = 0; start_iteration(tree, false, (void *)NULL, &assign_node_number); } static void assign_node_number(MMDBW_tree_s *tree, MMDBW_node_s *node, uint128_t UNUSED(network), uint8_t UNUSED(depth), void *UNUSED(args)) { node->number = tree->node_count++; return; } /* 16 bytes for an IP address, 1 byte for the prefix length */ #define FROZEN_RECORD_MAX_SIZE (16 + 1 + SHA1_KEY_LENGTH) #define FROZEN_NODE_MAX_SIZE (FROZEN_RECORD_MAX_SIZE * 2) /* 17 bytes of NULLs followed by something that cannot be an SHA1 key are a clear indicator that there are no more frozen networks in the buffer. */ #define SEVENTEEN_NULLS "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" #define FREEZE_SEPARATOR "not an SHA1 key" /* We subtract 1 as we treat this as a sequence of bytes rather than a null terminated string. */ #define FREEZE_SEPARATOR_LENGTH (sizeof(FREEZE_SEPARATOR) - 1) void freeze_tree(MMDBW_tree_s *tree, char *filename, char *frozen_params, size_t frozen_params_size) { FILE *file = fopen(filename, "wb"); if (!file) { croak("Could not open file %s: %s", filename, strerror(errno)); } freeze_args_s args = { .file = file, .filename = filename, }; freeze_to_file(&args, &frozen_params_size, 4); freeze_to_file(&args, frozen_params, frozen_params_size); freeze_search_tree(tree, &args); freeze_to_file(&args, SEVENTEEN_NULLS, 17); freeze_to_file(&args, FREEZE_SEPARATOR, FREEZE_SEPARATOR_LENGTH); freeze_data_to_file(&args, tree); if (fclose(file) != 0) { croak("Could not close file %s: %s", filename, strerror(errno)); } /* When the hash is _freed_, Perl decrements the ref count for each value * so we don't need to mess with them. */ SvREFCNT_dec((SV *)args.data_hash); } static void freeze_search_tree(MMDBW_tree_s *tree, freeze_args_s *args) { if (tree->root_record.type == MMDBW_RECORD_TYPE_DATA) { croak("A tree that only contains a data record for /0 cannot be " "frozen"); } if (tree->root_record.type == MMDBW_RECORD_TYPE_NODE || tree->root_record.type == MMDBW_RECORD_TYPE_FIXED_NODE) { start_iteration(tree, false, (void *)args, &freeze_node); return; } croak("Unexected root record type when freezing tree: %s", record_type_name(tree->root_record.type)); } static void freeze_node(MMDBW_tree_s *tree, MMDBW_node_s *node, uint128_t network, uint8_t depth, void *void_args) { freeze_args_s *args = (freeze_args_s *)void_args; const uint8_t next_depth = depth + 1; if (node->left_record.type == MMDBW_RECORD_TYPE_DATA) { freeze_data_record( tree, network, next_depth, node->left_record.value.key, args); } if (node->right_record.type == MMDBW_RECORD_TYPE_DATA) { uint128_t right_network = flip_network_bit(tree, network, depth); freeze_data_record(tree, right_network, next_depth, node->right_record.value.key, args); } } static void freeze_data_record(MMDBW_tree_s *UNUSED(tree), uint128_t network, uint8_t depth, const char *key, freeze_args_s *args) { /* It'd save some space to shrink this to 4 bytes for IPv4-only trees, but * that would also complicated thawing quite a bit. */ freeze_to_file(args, &network, 16); freeze_to_file(args, &(depth), 1); freeze_to_file(args, (char *)key, SHA1_KEY_LENGTH); } static void freeze_to_file(freeze_args_s *args, void *data, size_t size) { checked_fwrite(args->file, args->filename, data, size); } static void freeze_data_to_file(freeze_args_s *args, MMDBW_tree_s *tree) { HV *data_hash = newHV(); MMDBW_data_hash_s *item, *tmp; HASH_ITER(hh, tree->data_table, item, tmp) { SvREFCNT_inc_simple_void_NN(item->data_sv); (void)hv_store(data_hash, item->key, SHA1_KEY_LENGTH, item->data_sv, 0); } SV *frozen_data = freeze_hash(data_hash); STRLEN frozen_data_size; char *frozen_data_chars = SvPV(frozen_data, frozen_data_size); checked_fwrite( args->file, args->filename, &frozen_data_size, sizeof(STRLEN)); checked_fwrite( args->file, args->filename, frozen_data_chars, frozen_data_size); SvREFCNT_dec(frozen_data); SvREFCNT_dec((SV *)data_hash); } static SV *freeze_hash(HV *hash) { dSP; ENTER; SAVETMPS; SV *hashref = sv_2mortal(newRV_inc((SV *)hash)); PUSHMARK(SP); EXTEND(SP, 1); PUSHs(hashref); PUTBACK; int count = call_pv("Sereal::Encoder::encode_sereal", G_SCALAR); SPAGAIN; if (count != 1) { croak("Expected 1 item back from Sereal::Encoder::encode_sereal call"); } SV *frozen = POPs; if (!SvPOK(frozen)) { croak("The Sereal::Encoder::encode_sereal sub returned an SV which is " "not SvPOK!"); } /* The SV will be mortal so it's about to lose a ref with the FREETMPS call below. */ SvREFCNT_inc_simple_void_NN(frozen); PUTBACK; FREETMPS; LEAVE; return frozen; } MMDBW_tree_s *thaw_tree(char *filename, uint32_t initial_offset, uint8_t ip_version, uint8_t record_size, MMDBW_merge_strategy merge_strategy, const bool alias_ipv6, const bool remove_reserved_networks) { #ifdef WIN32 int fd = open(filename, O_RDONLY); #else int fd = open(filename, O_RDONLY, 0); #endif if (fd == -1) { croak("Could not open file %s: %s", filename, strerror(errno)); } struct stat fileinfo; if (fstat(fd, &fileinfo) == -1) { close(fd); croak("Could not stat file: %s: %s", filename, strerror(errno)); } uint8_t *buffer = (uint8_t *)mmap(NULL, fileinfo.st_size, PROT_READ, MAP_SHARED, fd, 0); close(fd); buffer += initial_offset; MMDBW_tree_s *tree = new_tree(ip_version, record_size, merge_strategy, alias_ipv6, remove_reserved_networks); thawed_network_s *thawed; while (NULL != (thawed = thaw_network(tree, &buffer))) { // We should never need to merge when thawing a tree. MMDBW_status status = insert_record_for_network(tree, thawed->network, thawed->record, MMDBW_MERGE_STRATEGY_NONE, true); free_network(thawed->network); free(thawed->network); if (thawed->record->type == MMDBW_RECORD_TYPE_DATA) { free((char *)thawed->record->value.key); } free(thawed->record); free(thawed); if (status != MMDBW_SUCCESS) { croak(status_error_message(status)); } } STRLEN frozen_data_size = thaw_strlen(&buffer); /* per perlapi newSVpvn copies the string */ SV *data_to_decode = sv_2mortal(newSVpvn((char *)buffer, frozen_data_size)); HV *data_hash = thaw_data_hash(data_to_decode); hv_iterinit(data_hash); char *key; I32 keylen; SV *value; while (NULL != (value = hv_iternextsv(data_hash, &key, &keylen))) { set_stored_data_in_tree(tree, key, value); } SvREFCNT_dec((SV *)data_hash); return tree; } static uint8_t thaw_uint8(uint8_t **buffer) { uint8_t value; memcpy(&value, *buffer, 1); *buffer += 1; return value; } static thawed_network_s *thaw_network(MMDBW_tree_s *tree, uint8_t **buffer) { uint128_t start_ip = thaw_uint128(buffer); uint8_t prefix_length = thaw_uint8(buffer); if (start_ip == 0 && prefix_length == 0) { uint8_t *maybe_separator = thaw_bytes(buffer, FREEZE_SEPARATOR_LENGTH); if (memcmp(maybe_separator, FREEZE_SEPARATOR, FREEZE_SEPARATOR_LENGTH) == 0) { free(maybe_separator); return NULL; } croak("Found a ::0/0 network but that should never happen!"); } uint8_t *start_ip_bytes = (uint8_t *)&start_ip; uint8_t temp; for (int i = 0; i < 8; i++) { temp = start_ip_bytes[i]; start_ip_bytes[i] = start_ip_bytes[15 - i]; start_ip_bytes[15 - i] = temp; } thawed_network_s *thawed = checked_malloc(sizeof(thawed_network_s)); uint8_t *bytes; if (tree->ip_version == 4) { bytes = checked_malloc(4); memcpy(bytes, start_ip_bytes + 12, 4); } else { bytes = checked_malloc(16); memcpy(bytes, &start_ip, 16); } MMDBW_network_s network = { .bytes = bytes, .prefix_length = prefix_length, }; thawed->network = checked_malloc(sizeof(MMDBW_network_s)); memcpy(thawed->network, &network, sizeof(MMDBW_network_s)); MMDBW_record_s *record = checked_malloc(sizeof(MMDBW_record_s)); record->type = MMDBW_RECORD_TYPE_DATA; record->value.key = thaw_data_key(buffer); thawed->record = record; return thawed; } static uint8_t *thaw_bytes(uint8_t **buffer, size_t size) { uint8_t *value = checked_malloc(size); memcpy(value, *buffer, size); *buffer += size; return value; } static uint128_t thaw_uint128(uint8_t **buffer) { uint128_t value; memcpy(&value, *buffer, 16); *buffer += 16; return value; } static STRLEN thaw_strlen(uint8_t **buffer) { STRLEN value; memcpy(&value, *buffer, sizeof(STRLEN)); *buffer += sizeof(STRLEN); return value; } static const char *thaw_data_key(uint8_t **buffer) { char *value = checked_malloc(SHA1_KEY_LENGTH + 1); memcpy(value, *buffer, SHA1_KEY_LENGTH); *buffer += SHA1_KEY_LENGTH; value[SHA1_KEY_LENGTH] = '\0'; return (const char *)value; } static HV *thaw_data_hash(SV *data_to_decode) { dSP; ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP, 1); PUSHs(data_to_decode); PUTBACK; int count = call_pv("Sereal::Decoder::decode_sereal", G_SCALAR); SPAGAIN; if (count != 1) { croak("Expected 1 item back from Sereal::Decoder::decode_sereal call"); } SV *thawed = POPs; if (!SvROK(thawed)) { croak("The Sereal::Decoder::decode_sereal sub returned an SV which is " "not SvROK!"); } SV *data_hash = SvREFCNT_inc_simple_NN(SvRV(thawed)); PUTBACK; FREETMPS; LEAVE; return (HV *)data_hash; } void write_search_tree(MMDBW_tree_s *tree, SV *output, SV *root_data_type, SV *serializer) { assign_node_numbers(tree); /* This is a gross way to get around the fact that with C function * pointers we can't easily pass different params to different * callbacks. */ encode_args_s args = {.output_io = IoOFP(sv_2io(output)), .root_data_type = root_data_type, .serializer = serializer, .data_pointer_cache = newHV()}; start_iteration(tree, false, (void *)&args, &encode_node); /* When the hash is _freed_, Perl decrements the ref count for each value * so we don't need to mess with them. */ SvREFCNT_dec((SV *)args.data_pointer_cache); return; } static void encode_node(MMDBW_tree_s *tree, MMDBW_node_s *node, uint128_t UNUSED(network), uint8_t UNUSED(depth), void *void_args) { encode_args_s *args = (encode_args_s *)void_args; check_record_sanity(node, &(node->left_record), "left"); check_record_sanity(node, &(node->right_record), "right"); uint32_t left = htonl(record_value_as_number(tree, &(node->left_record), args)); uint32_t right = htonl(record_value_as_number(tree, &(node->right_record), args)); uint8_t *left_bytes = (uint8_t *)&left; uint8_t *right_bytes = (uint8_t *)&right; if (tree->record_size == 24) { check_perlio_result(PerlIO_printf(args->output_io, "%c%c%c%c%c%c", left_bytes[1], left_bytes[2], left_bytes[3], right_bytes[1], right_bytes[2], right_bytes[3]), 6, "PerlIO_printf"); } else if (tree->record_size == 28) { check_perlio_result( PerlIO_printf(args->output_io, "%c%c%c%c%c%c%c", left_bytes[1], left_bytes[2], left_bytes[3], (left_bytes[0] << 4) | (right_bytes[0] & 15), right_bytes[1], right_bytes[2], right_bytes[3]), 7, "PerlIO_printf"); } else { check_perlio_result(PerlIO_printf(args->output_io, "%c%c%c%c%c%c%c%c", left_bytes[0], left_bytes[1], left_bytes[2], left_bytes[3], right_bytes[0], right_bytes[1], right_bytes[2], right_bytes[3]), 8, "PerlIO_printf"); } } /* Note that for data records, we will ensure that the key they contain does * match a data record in the record_value_as_number() subroutine. */ static void check_record_sanity(MMDBW_node_s *node, MMDBW_record_s *record, char *side) { if (record->type == MMDBW_RECORD_TYPE_NODE || record->type == MMDBW_RECORD_TYPE_FIXED_NODE) { if (record->value.node->number == node->number) { croak("%s record of node %" PRIu32 " points to the same node", side, node->number); } if (record->value.node->number < node->number) { croak("%s record of node %" PRIu32 " points to a node number (%" PRIu32 ")", side, node->number, record->value.node->number); } } // This is a simple check that we aren't pointing at the tree root. if (record->type == MMDBW_RECORD_TYPE_ALIAS) { if (record->value.node->number == 0) { croak("%s record of node %" PRIu32 " is an alias to node 0", side, node->number); } } } static uint32_t record_value_as_number(MMDBW_tree_s *tree, MMDBW_record_s *record, encode_args_s *args) { uint32_t record_value = 0; switch (record->type) { case MMDBW_RECORD_TYPE_FIXED_EMPTY: case MMDBW_RECORD_TYPE_EMPTY: { // Say that the IP isn't here. record_value = tree->node_count; break; } case MMDBW_RECORD_TYPE_NODE: case MMDBW_RECORD_TYPE_ALIAS: case MMDBW_RECORD_TYPE_FIXED_NODE: { record_value = record->value.node->number; break; } case MMDBW_RECORD_TYPE_DATA: { SV **cache_record = hv_fetch(args->data_pointer_cache, record->value.key, SHA1_KEY_LENGTH, 0); if (cache_record) { /* It is ok to return this without the size check below as it would have already croaked when it was inserted if it was too big. */ return SvIV(*cache_record); } SV *data = newSVsv(data_for_key(tree, record->value.key)); if (!SvOK(data)) { croak("No data associated with key - %s", record->value.key); } dSP; ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP, 5); PUSHs(args->serializer); PUSHs(args->root_data_type); mPUSHs(data); PUSHs(&PL_sv_undef); mPUSHp(record->value.key, strlen(record->value.key)); PUTBACK; int count = call_method("store_data", G_SCALAR); SPAGAIN; if (count != 1) { croak("Expected 1 item back from ->store_data() call"); } SV *rval = POPs; if (!(SvIOK(rval) || SvUOK(rval))) { croak("The serializer's store_data() method returned an SV " "which is not SvIOK or SvUOK!"); } uint32_t position = (uint32_t)SvUV(rval); PUTBACK; FREETMPS; LEAVE; record_value = position + tree->node_count + DATA_SECTION_SEPARATOR_SIZE; SV *value = newSViv(record_value); (void)hv_store(args->data_pointer_cache, record->value.key, SHA1_KEY_LENGTH, value, 0); break; } } if (record_value > max_record_value(tree)) { croak("Node value of %" PRIu32 " exceeds the record size of %" PRIu8 " bits", record_value, tree->record_size); } return record_value; } uint32_t max_record_value(MMDBW_tree_s *tree) { uint8_t record_size = tree->record_size; return record_size == 32 ? UINT32_MAX : (uint32_t)(1 << record_size) - 1; } void start_iteration(MMDBW_tree_s *tree, bool depth_first, void *args, MMDBW_iterator_callback callback) { uint128_t network = 0; uint8_t depth = 0; // We disallow this as the callback is based on nodes rather than records, // and changing that is a rabbit hole that I don't want to go down // currently. (I stuck my head in and regretted it.) if (MMDBW_RECORD_TYPE_NODE != tree->root_record.type && MMDBW_RECORD_TYPE_FIXED_NODE != tree->root_record.type) { croak("Iteration is not currently allowed in trees with no nodes. " "Record type: %s", record_type_name(tree->root_record.type)); } iterate_tree( tree, &tree->root_record, network, depth, depth_first, args, callback); return; } static void iterate_tree(MMDBW_tree_s *tree, MMDBW_record_s *record, uint128_t network, const uint8_t depth, bool depth_first, void *args, MMDBW_iterator_callback callback) { if (depth > tree_depth0(tree) + 1) { char ip[INET6_ADDRSTRLEN]; integer_to_ip_string(tree->ip_version, network, ip, sizeof(ip)); croak("Depth during iteration is greater than 127 (depth: %u, " "start IP: %s)! The tree is wonky.\n", depth, ip); } if (record->type == MMDBW_RECORD_TYPE_NODE || record->type == MMDBW_RECORD_TYPE_FIXED_NODE) { MMDBW_node_s *node = record->value.node; if (!depth_first) { callback(tree, node, network, depth, args); } iterate_tree(tree, &node->left_record, network, depth + 1, depth_first, args, callback); if (depth_first) { callback(tree, node, network, depth, args); } iterate_tree(tree, &node->right_record, flip_network_bit(tree, network, depth), depth + 1, depth_first, args, callback); } } uint128_t flip_network_bit(MMDBW_tree_s *tree, uint128_t network, uint8_t depth) { return network | ((uint128_t)1 << (tree_depth0(tree) - depth)); } static SV *key_for_data(SV *data) { dSP; ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP, 1); PUSHs(data); PUTBACK; const char *const sub = "MaxMind::DB::Writer::Util::key_for_data"; int count = call_pv(sub, G_SCALAR); SPAGAIN; if (count != 1) { croak("Expected 1 item back from %s() call", sub); } SV *key = POPs; SvREFCNT_inc_simple_void_NN(key); PUTBACK; FREETMPS; LEAVE; return key; } SV *data_for_key(MMDBW_tree_s *tree, const char *const key) { MMDBW_data_hash_s *data = NULL; HASH_FIND(hh, tree->data_table, key, strlen(key), data); if (NULL != data) { return data->data_sv; } else { return &PL_sv_undef; } } static const char *merge_cache_lookup(MMDBW_tree_s *tree, char *merge_cache_key) { MMDBW_merge_cache_s *cache = NULL; HASH_FIND(hh, tree->merge_cache, merge_cache_key, MERGE_KEY_SIZE, cache); if (!cache) { return NULL; } // We have to check that the value has not been removed from the data // table MMDBW_data_hash_s *data = NULL; HASH_FIND(hh, tree->data_table, cache->value, SHA1_KEY_LENGTH, data); if (data != NULL) { return cache->value; } // Item has been removed from data table. Remove the cached merge too. HASH_DEL(tree->merge_cache, cache); return NULL; } static void store_in_merge_cache(MMDBW_tree_s *tree, char *merge_cache_key, const char *const new_key) { MMDBW_merge_cache_s *data = checked_malloc(sizeof(MMDBW_merge_cache_s)); data->value = checked_malloc(SHA1_KEY_LENGTH + 1); strncpy((char *)data->value, new_key, SHA1_KEY_LENGTH + 1); data->key = checked_malloc(MERGE_KEY_SIZE + 1); strncpy((char *)data->key, merge_cache_key, MERGE_KEY_SIZE + 1); HASH_ADD_KEYPTR(hh, tree->merge_cache, data->key, MERGE_KEY_SIZE, data); } void free_tree(MMDBW_tree_s *tree) { free_record_value(tree, &tree->root_record, true); free_merge_cache(tree); int hash_count = HASH_COUNT(tree->data_table); if (0 != hash_count) { croak("%d elements left in data table after freeing all nodes!", hash_count); } free(tree); } void free_merge_cache(MMDBW_tree_s *tree) { MMDBW_merge_cache_s *cache, *tmp = NULL; HASH_ITER(hh, tree->merge_cache, cache, tmp) { HASH_DEL(tree->merge_cache, cache); free((void *)cache->key); free((void *)cache->value); free(cache); } } static void *checked_malloc(size_t size) { void *ptr = malloc(size); if (!ptr) { abort(); } return ptr; } static void checked_fwrite(FILE *file, char *filename, void *buffer, size_t count) { size_t result = fwrite(buffer, 1, count, file); if (result != count) { fclose(file); croak("Write to %s did not write the expected amount of data (wrote " "%zu instead of %zu): %s", filename, result, count, strerror(errno)); } } static void check_perlio_result(SSize_t result, SSize_t expected, char *op) { if (result < 0) { croak("%s operation failed: %s\n", op, strerror(result)); } else if (result != expected) { croak("%s operation wrote %zd bytes when we expected to write %zd", op, result, expected); } } static char *status_error_message(MMDBW_status status) { switch (status) { case MMDBW_SUCCESS: return "Success"; case MMDBW_INSERT_INTO_ALIAS_NODE_ERROR: return "Attempted to insert into an aliased network."; case MMDBW_INSERT_INVALID_RECORD_TYPE_ERROR: return "Invalid record type given to insert."; case MMDBW_FREED_ALIAS_NODE_ERROR: return "Attempted to free an IPv4 alias node. Did you try to " "overwrite an alias network?"; case MMDBW_FREED_FIXED_EMPTY_ERROR: return "Attempted to free a fixed empty node. This should never " "happen."; case MMDBW_FREED_FIXED_NODE_ERROR: return "Attempted to free a fixed node. This should never happen."; case MMDBW_ALIAS_OVERWRITE_ATTEMPT_ERROR: return "Attempted to overwrite an aliased network."; case MMDBW_FIXED_NODE_OVERWRITE_ATTEMPT_ERROR: return "Attempted to overwrite a fixed node."; case MMDBW_RESOLVING_IP_ERROR: return "Failed to resolve IP address."; } // We should get a compile time warning if an enum is missing return "Unknown error"; } static const char *record_type_name(MMDBW_record_type type) { switch (type) { case MMDBW_RECORD_TYPE_EMPTY: return "empty"; case MMDBW_RECORD_TYPE_FIXED_EMPTY: return "fixed_empty"; case MMDBW_RECORD_TYPE_DATA: return "data"; case MMDBW_RECORD_TYPE_NODE: return "node"; case MMDBW_RECORD_TYPE_FIXED_NODE: return "fixed_node"; case MMDBW_RECORD_TYPE_ALIAS: return "alias"; } return "unknown type"; } tree.h100644000000000000 1531613321164704 15572 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/c#include "EXTERN.h" #include "perl.h" // It is crucial that XSUB.h comes after perl.h. #include "XSUB.h" #include #include #include #ifdef INT64_T #define HAVE_INT64 #endif #ifdef __INT64 typedef __int64 int64_t; typedef unsigned __int64 uint64_t; #define HAVE_INT64 #endif #ifdef INT64_DI typedef int int64_t __attribute__((__mode__(DI))); typedef unsigned int uint64_t __attribute__((__mode__(DTI))); #define HAVE_INT64 #endif #ifndef HAVE_INT64 #error "No int64 type define was passed to the compiler!" #endif #ifdef INT128_TI typedef int int128_t __attribute__((__mode__(TI))); typedef unsigned int uint128_t __attribute__((__mode__(TI))); #define HAVE_INT128 #endif #ifdef __INT128 typedef __int128 int128_t; typedef unsigned __int128 uint128_t; #define HAVE_INT128 #endif #ifndef HAVE_INT128 #error "No int128 type define was passed to the compiler!" #endif /* perl memory allocator does not guarantee 16-byte alignment */ typedef int128_t int128_t_a8 __attribute__((aligned(8))); typedef uint128_t uint128_t_a8 __attribute__((aligned(8))); #define MATH_INT64_NATIVE_IF_AVAILABLE #include "perl_math_int128.h" #include "perl_math_int64.h" typedef enum { MMDBW_SUCCESS, MMDBW_INSERT_INTO_ALIAS_NODE_ERROR, MMDBW_INSERT_INVALID_RECORD_TYPE_ERROR, MMDBW_FREED_ALIAS_NODE_ERROR, MMDBW_FREED_FIXED_EMPTY_ERROR, MMDBW_FREED_FIXED_NODE_ERROR, MMDBW_ALIAS_OVERWRITE_ATTEMPT_ERROR, MMDBW_FIXED_NODE_OVERWRITE_ATTEMPT_ERROR, MMDBW_RESOLVING_IP_ERROR, } MMDBW_status; typedef enum { MMDBW_RECORD_TYPE_EMPTY, // Fixed empty records are like empty records in that they say there is no // information. They are also immutable. And similar to alias records, you // can't replace them, insert networks containing them, or insert networks // belonging to them. // // We can't use EMPTY because they are not immutable. We can't use // FIXED_NODE because they allow children (adding sub-networks). We can't // use ALIAS as it has a special meaning, and we don't permit lookups to // work (although that is only used in test code apparently). They also // raise errors in some cases where FIXED_EMPTY currently does not. MMDBW_RECORD_TYPE_FIXED_EMPTY, MMDBW_RECORD_TYPE_DATA, MMDBW_RECORD_TYPE_NODE, // Fixed nodes are used for nodes that other nodes alias; they cannot be // removed without corrupting the tree. Unlike FIXED_EMPTY, they can have // children. MMDBW_RECORD_TYPE_FIXED_NODE, MMDBW_RECORD_TYPE_ALIAS, } MMDBW_record_type; typedef enum { MMDBW_MERGE_STRATEGY_UNKNOWN, MMDBW_MERGE_STRATEGY_NONE, MMDBW_MERGE_STRATEGY_TOPLEVEL, MMDBW_MERGE_STRATEGY_RECURSE, MMDBW_MERGE_STRATEGY_ADD_ONLY_IF_PARENT_EXISTS } MMDBW_merge_strategy; typedef struct MMDBW_record_s { union { // Data records have a key into the tree's data table, a hash. const char *key; struct MMDBW_node_s *node; } value; MMDBW_record_type type; } MMDBW_record_s; typedef struct MMDBW_node_s { MMDBW_record_s left_record; MMDBW_record_s right_record; uint32_t number; } MMDBW_node_s; typedef struct MMDBW_data_hash_s { SV *data_sv; const char *key; uint32_t reference_count; UT_hash_handle hh; } MMDBW_data_hash_s; typedef struct MMDBW_merge_cache_s { const char *key; const char *value; UT_hash_handle hh; } MMDBW_merge_cache_s; typedef struct MMDBW_tree_s { uint8_t ip_version; uint8_t record_size; MMDBW_merge_strategy merge_strategy; MMDBW_data_hash_s *data_table; MMDBW_merge_cache_s *merge_cache; MMDBW_record_s root_record; uint32_t node_count; } MMDBW_tree_s; typedef struct MMDBW_network_s { const uint8_t *const bytes; const uint8_t prefix_length; } MMDBW_network_s; typedef void(MMDBW_iterator_callback)(MMDBW_tree_s *tree, MMDBW_node_s *node, uint128_t network, uint8_t depth, void *args); extern MMDBW_tree_s *new_tree(const uint8_t ip_version, uint8_t record_size, MMDBW_merge_strategy merge_strategy, const bool alias_ipv6, const bool remove_reserved_networks); extern void insert_network(MMDBW_tree_s *tree, const char *ipstr, const uint8_t prefix_length, SV *key_sv, SV *data, MMDBW_merge_strategy merge_strategy); extern void insert_range(MMDBW_tree_s *tree, const char *start_ipstr, const char *end_ipstr, SV *key_sv, SV *data_sv, MMDBW_merge_strategy merge_strategy); extern void remove_network(MMDBW_tree_s *tree, const char *ipstr, const uint8_t prefix_length); extern SV *merge_hashes_for_keys(MMDBW_tree_s *tree, const char *const key_from, const char *const key_into, MMDBW_network_s *network, MMDBW_merge_strategy merge_strategy); extern SV *lookup_ip_address(MMDBW_tree_s *tree, const char *const ipstr); extern MMDBW_node_s *new_node(); extern void assign_node_numbers(MMDBW_tree_s *tree); extern void freeze_tree(MMDBW_tree_s *tree, char *filename, char *frozen_params, size_t frozen_params_size); extern MMDBW_tree_s *thaw_tree(char *filename, uint32_t initial_offset, uint8_t ip_version, uint8_t record_size, MMDBW_merge_strategy merge_strategy, const bool alias_ipv6, const bool remove_reserved_networks); extern void write_search_tree(MMDBW_tree_s *tree, SV *output, SV *root_data_type, SV *serializer); extern uint32_t max_record_value(MMDBW_tree_s *tree); extern void start_iteration(MMDBW_tree_s *tree, bool depth_first, void *args, MMDBW_iterator_callback callback); extern uint128_t flip_network_bit(MMDBW_tree_s *tree, uint128_t network, uint8_t depth); extern SV *data_for_key(MMDBW_tree_s *tree, const char *const key); extern void free_tree(MMDBW_tree_s *tree); extern void free_merge_cache(MMDBW_tree_s *tree); dist.ini100644000000000000 134413321164704 15660 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003name = MaxMind-DB-Writer author = Olaf Alders author = Greg Oschwald author = Dave Rolsky author = Mark Fowler [@MAXMIND] dist = MaxMind-DB-Writer make_tool = ModuleBuild prereqs_skip = GraphViz2 stopwords = CIDR stopwords = docs stopwords = en stopwords = GeoIP stopwords = MMDB stopwords = routable stopwords = Teredo stopwords = toplevel stopwords = TW stopwords = uint stopwords = zh -remove = ModuleBuild -remove = Test::Compile -remove = Test::Pod::Coverage::Configurable -remove = Test::TidyAll PPPort.filename = c/ppport.h Test::CleanNamespaces.skip = MaxMind::DB::Writer::Util [=inc::MyModuleBuild] [Prereqs / DevelopRequires] JSON = 0 MANIFEST100644000000000000 553213321164704 15350 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.012. Build.PL CONTRIBUTING.md Changes INSTALL LICENSE MANIFEST META.json META.yml README.md bench/memory-use c/perl_math_int128.c c/perl_math_int128.h c/perl_math_int64.c c/perl_math_int64.h c/ppport.h c/tree.c c/tree.h c/uthash.h c/windows_mman.c c/windows_mman.h cpanfile dev-bin/clang-format-all.sh dist.ini eg/freeze-thaw inc/Capture/Tiny.pm inc/Config/AutoConf.pm inc/MyModuleBuild.pm lib/MaxMind/DB/Writer.pm lib/MaxMind/DB/Writer/Serializer.pm lib/MaxMind/DB/Writer/Tree.pm lib/MaxMind/DB/Writer/Tree.xs lib/MaxMind/DB/Writer/Tree/Processor/VisualizeTree.pm lib/MaxMind/DB/Writer/Util.pm lib/MaxMind/DB/Writer/typemap perlcriticrc perltidyrc t/00-report-prereqs.dd t/00-report-prereqs.t t/MaxMind/DB/Writer/Serializer-deduplication.t t/MaxMind/DB/Writer/Serializer-large-pointer.t t/MaxMind/DB/Writer/Serializer-types/array.t t/MaxMind/DB/Writer/Serializer-types/boolean.t t/MaxMind/DB/Writer/Serializer-types/bytes.t t/MaxMind/DB/Writer/Serializer-types/double.t t/MaxMind/DB/Writer/Serializer-types/end_marker.t t/MaxMind/DB/Writer/Serializer-types/float.t t/MaxMind/DB/Writer/Serializer-types/int32.t t/MaxMind/DB/Writer/Serializer-types/map.t t/MaxMind/DB/Writer/Serializer-types/pointer.t t/MaxMind/DB/Writer/Serializer-types/uint128.t t/MaxMind/DB/Writer/Serializer-types/uint16.t t/MaxMind/DB/Writer/Serializer-types/uint32.t t/MaxMind/DB/Writer/Serializer-types/uint64.t t/MaxMind/DB/Writer/Serializer-types/utf8_string.t t/MaxMind/DB/Writer/Serializer-utf8-as-bytes.t t/MaxMind/DB/Writer/Serializer-utf8-round-trip.t t/MaxMind/DB/Writer/Serializer.t t/MaxMind/DB/Writer/Tree-bigint.t t/MaxMind/DB/Writer/Tree-data-references.t t/MaxMind/DB/Writer/Tree-freeze-thaw.t t/MaxMind/DB/Writer/Tree-insert-range.t t/MaxMind/DB/Writer/Tree-ipv4-and-6.t t/MaxMind/DB/Writer/Tree-ipv6-aliases.t t/MaxMind/DB/Writer/Tree-iterator-large-dataset.t t/MaxMind/DB/Writer/Tree-iterator.t t/MaxMind/DB/Writer/Tree-output/0-0-0-0.t t/MaxMind/DB/Writer/Tree-output/basic.t t/MaxMind/DB/Writer/Tree-output/freeze-thaw-record-size.t t/MaxMind/DB/Writer/Tree-output/freeze-then-write-bug.t t/MaxMind/DB/Writer/Tree-output/ipv6-aliases.t t/MaxMind/DB/Writer/Tree-output/record-deduplication.t t/MaxMind/DB/Writer/Tree-output/utf8-data.t t/MaxMind/DB/Writer/Tree-record-collisions.t t/MaxMind/DB/Writer/Tree-thaw-merge.t t/MaxMind/DB/Writer/Tree.t t/MaxMind/DB/Writer/Util.t t/lib/Test/MaxMind/DB/Writer.pm t/lib/Test/MaxMind/DB/Writer/Iterator.pm t/lib/Test/MaxMind/DB/Writer/Serializer.pm t/test-data/geolite2-sample.json tidyall.ini valgrind.supp xt/author/Tree-freeze-thaw-large-tree.t xt/author/clean-namespaces.t xt/author/eol.t xt/author/mojibake.t xt/author/no-tabs.t xt/author/pod-spell.t xt/author/pod-syntax.t xt/author/portability.t xt/author/synopsis.t xt/author/test-version.t xt/release/cpan-changes.t xt/release/meta-json.t META.yml100644000000000000 5546413321164704 15521 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003--- abstract: 'Create MaxMind DB database files' author: - 'Olaf Alders ' - 'Greg Oschwald ' - 'Dave Rolsky ' - 'Mark Fowler ' build_requires: Data::Printer: '0' Devel::Refcount: '0' ExtUtils::MakeMaker: '0' File::Spec: '0' File::Temp: '0' JSON: '0' List::AllUtils: '0' List::Util: '0' MaxMind::DB::Reader: '0' Module::Build: '0.28' Net::Works::Address: '0' Scalar::Util: '0' Test::Bits: '0' Test::Builder: '0' Test::Fatal: '0' Test::HexDifferences: '0' Test::MaxMind::DB::Common::Data: '0' Test::More: '0.96' Test::Requires: '0' Test::Warnings: '0' lib: '0' utf8: '0' configure_requires: Module::Build: '0.28' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.012, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: MaxMind-DB-Writer provides: MaxMind::DB::Writer: file: lib/MaxMind/DB/Writer.pm version: '0.300003' MaxMind::DB::Writer::Serializer: file: lib/MaxMind/DB/Writer/Serializer.pm version: '0.300003' MaxMind::DB::Writer::Tree: file: lib/MaxMind/DB/Writer/Tree.pm version: '0.300003' MaxMind::DB::Writer::Tree::Processor::VisualizeTree: file: lib/MaxMind/DB/Writer/Tree/Processor/VisualizeTree.pm version: '0.300003' MaxMind::DB::Writer::Util: file: lib/MaxMind/DB/Writer/Util.pm version: '0.300003' requires: Carp: '0' Data::Dumper::Concise: '0' Data::IEEE754: '0' Digest::MD5: '0' Digest::SHA1: '0' Encode: '0' Exporter: '0' IO::Handle: '0' Math::Int128: '0.21' Math::Int64: '0.51' MaxMind::DB::Common: '0.031003' MaxMind::DB::Metadata: '0' MaxMind::DB::Reader::Decoder: '0' MaxMind::DB::Role::Debugs: '0' Moose: '0' Moose::Util::TypeConstraints: '0' MooseX::Params::Validate: '0' MooseX::StrictConstructor: '0' Net::Works::Network: '0' Sereal::Decoder: '0' Sereal::Encoder: '3.002' Test::Deep::NoTest: '0' XSLoader: '0' autodie: '0' bytes: '0' constant: '0' namespace::autoclean: '0' perl: '5.013002' strict: '0' warnings: '0' resources: bugtracker: https://github.com/maxmind/MaxMind-DB-Writer-perl/issues homepage: http://metacpan.org/release/MaxMind-DB-Writer repository: git://github.com/maxmind/MaxMind-DB-Writer-perl.git version: '0.300003' x_Dist_Zilla: perl: version: '5.026001' plugins: - class: Dist::Zilla::Plugin::Git::GatherDir config: Dist::Zilla::Plugin::GatherDir: exclude_filename: - Build.PL - CONTRIBUTING.md - LICENSE - README.md - c/ppport.h - cpanfile exclude_match: [] follow_symlinks: 0 include_dotfiles: 0 prefix: '' prune_directory: [] root: . Dist::Zilla::Plugin::Git::GatherDir: include_untracked: 0 name: '@MAXMIND/Git::GatherDir' version: '2.045' - class: Dist::Zilla::Plugin::ManifestSkip name: '@MAXMIND/ManifestSkip' version: '6.012' - class: Dist::Zilla::Plugin::License name: '@MAXMIND/License' version: '6.012' - class: Dist::Zilla::Plugin::ExecDir name: '@MAXMIND/ExecDir' version: '6.012' - class: Dist::Zilla::Plugin::ShareDir name: '@MAXMIND/ShareDir' version: '6.012' - class: Dist::Zilla::Plugin::Manifest name: '@MAXMIND/Manifest' version: '6.012' - class: Dist::Zilla::Plugin::CheckVersionIncrement name: '@MAXMIND/CheckVersionIncrement' version: '0.121750' - class: Dist::Zilla::Plugin::TestRelease name: '@MAXMIND/TestRelease' version: '6.012' - class: Dist::Zilla::Plugin::ConfirmRelease name: '@MAXMIND/ConfirmRelease' version: '6.012' - class: Dist::Zilla::Plugin::MAXMIND::VersionProvider name: '@MAXMIND/MAXMIND::VersionProvider' version: '0.83' - class: Dist::Zilla::Plugin::Authority name: '@MAXMIND/Authority' version: '1.009' - class: Dist::Zilla::Plugin::AutoPrereqs name: '@MAXMIND/AutoPrereqs' version: '6.012' - class: Dist::Zilla::Plugin::CopyFilesFromBuild name: '@MAXMIND/CopyFilesFromBuild' version: '0.170880' - class: Dist::Zilla::Plugin::GitHub::Meta name: '@MAXMIND/GitHub::Meta' version: '0.45' - class: Dist::Zilla::Plugin::GitHub::Update config: Dist::Zilla::Plugin::GitHub::Update: metacpan: 1 name: '@MAXMIND/GitHub::Update' version: '0.45' - class: Dist::Zilla::Plugin::MetaResources name: '@MAXMIND/MetaResources' version: '6.012' - class: Dist::Zilla::Plugin::MetaProvides::Package config: Dist::Zilla::Plugin::MetaProvides::Package: finder_objects: - class: Dist::Zilla::Plugin::FinderCode name: '@MAXMIND/MetaProvides::Package/AUTOVIV/:InstallModulesPM' version: '6.012' include_underscores: 0 Dist::Zilla::Role::MetaProvider::Provider: $Dist::Zilla::Role::MetaProvider::Provider::VERSION: '2.002004' inherit_missing: '1' inherit_version: '1' meta_noindex: '1' Dist::Zilla::Role::ModuleMetadata: Module::Metadata: '1.000033' version: '0.006' name: '@MAXMIND/MetaProvides::Package' version: '2.004003' - class: Dist::Zilla::Plugin::Meta::Contributors name: '@MAXMIND/Meta::Contributors' version: '0.003' - class: Dist::Zilla::Plugin::MetaConfig name: '@MAXMIND/MetaConfig' version: '6.012' - class: Dist::Zilla::Plugin::MetaJSON name: '@MAXMIND/MetaJSON' version: '6.012' - class: Dist::Zilla::Plugin::MetaYAML name: '@MAXMIND/MetaYAML' version: '6.012' - class: Dist::Zilla::Plugin::NextRelease name: '@MAXMIND/NextRelease' version: '6.012' - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: test type: requires name: '@MAXMIND/Test::More with subtest' version: '6.012' - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: develop type: requires name: '@MAXMIND/Modules for use with tidyall' version: '6.012' - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: develop type: requires name: '@MAXMIND/Test::Version which fixes https://github.com/plicease/Test-Version/issues/7' version: '6.012' - class: Dist::Zilla::Plugin::PromptIfStale config: Dist::Zilla::Plugin::PromptIfStale: check_all_plugins: 0 check_all_prereqs: 0 modules: - Dist::Zilla::PluginBundle::MAXMIND phase: build run_under_travis: 0 skip: [] name: '@MAXMIND/Dist::Zilla::PluginBundle::MAXMIND' version: '0.055' - class: Dist::Zilla::Plugin::PromptIfStale config: Dist::Zilla::Plugin::PromptIfStale: check_all_plugins: 1 check_all_prereqs: 1 modules: [] phase: release run_under_travis: 0 skip: - Dist::Zilla::Plugin::MAXMIND::CheckChangesHasContent - Dist::Zilla::Plugin::MAXMIND::Contributors - Dist::Zilla::Plugin::MAXMIND::Git::CheckFor::CorrectBranch - Dist::Zilla::Plugin::MAXMIND::License - Dist::Zilla::Plugin::MAXMIND::TidyAll - Dist::Zilla::Plugin::MAXMIND::VersionProvider - Pod::Weaver::PluginBundle::MAXMIND name: '@MAXMIND/PromptIfStale' version: '0.055' - class: Dist::Zilla::Plugin::Test::PodSpelling config: Dist::Zilla::Plugin::Test::PodSpelling: directories: - bin - lib spell_cmd: '' stopwords: - Alders - "Alders'" - CIDR - Eilam - "Eilam's" - GeoIP - MAXMIND - "MAXMIND's" - MMDB - MaxMind - "MaxMind's" - Oschwald - "Oschwald's" - PayPal - Rolsky - "Rolsky's" - TW - Teredo - docs - en - routable - toplevel - uint - zh wordlist: Pod::Wordlist name: '@MAXMIND/Test::PodSpelling' version: '2.007005' - class: Dist::Zilla::Plugin::PodSyntaxTests name: '@MAXMIND/PodSyntaxTests' version: '6.012' - class: Dist::Zilla::Plugin::RunExtraTests config: Dist::Zilla::Role::TestRunner: default_jobs: 1 name: '@MAXMIND/RunExtraTests' version: '0.029' - class: Dist::Zilla::Plugin::MojibakeTests name: '@MAXMIND/MojibakeTests' version: '0.8' - class: Dist::Zilla::Plugin::Test::CleanNamespaces config: Dist::Zilla::Plugin::Test::CleanNamespaces: filename: xt/author/clean-namespaces.t skips: - MaxMind::DB::Writer::Util name: '@MAXMIND/Test::CleanNamespaces' version: '0.006' - class: Dist::Zilla::Plugin::Test::CPAN::Changes config: Dist::Zilla::Plugin::Test::CPAN::Changes: changelog: Changes name: '@MAXMIND/Test::CPAN::Changes' version: '0.012' - class: Dist::Zilla::Plugin::Test::CPAN::Meta::JSON name: '@MAXMIND/Test::CPAN::Meta::JSON' version: '0.004' - class: Dist::Zilla::Plugin::Test::EOL config: Dist::Zilla::Plugin::Test::EOL: filename: xt/author/eol.t finder: - ':ExecFiles' - ':InstallModules' - ':TestFiles' trailing_whitespace: 1 name: '@MAXMIND/Test::EOL' version: '0.19' - class: Dist::Zilla::Plugin::Test::NoTabs config: Dist::Zilla::Plugin::Test::NoTabs: filename: xt/author/no-tabs.t finder: - ':InstallModules' - ':ExecFiles' - ':TestFiles' name: '@MAXMIND/Test::NoTabs' version: '0.15' - class: Dist::Zilla::Plugin::Test::Portability config: Dist::Zilla::Plugin::Test::Portability: options: '' name: '@MAXMIND/Test::Portability' version: '2.001000' - class: Dist::Zilla::Plugin::Test::Synopsis name: '@MAXMIND/Test::Synopsis' version: '2.000007' - class: Dist::Zilla::Plugin::Test::ReportPrereqs name: '@MAXMIND/Test::ReportPrereqs' version: '0.027' - class: Dist::Zilla::Plugin::Test::Version name: '@MAXMIND/Test::Version' version: '1.09' - class: Dist::Zilla::Plugin::MAXMIND::Contributors name: '@MAXMIND/MAXMIND::Contributors' version: '0.83' - class: Dist::Zilla::Plugin::Git::Contributors config: Dist::Zilla::Plugin::Git::Contributors: git_version: 2.17.1 include_authors: 0 include_releaser: 1 order_by: name paths: [] name: '@MAXMIND/Git::Contributors' version: '0.034' - class: Dist::Zilla::Plugin::SurgicalPodWeaver config: Dist::Zilla::Plugin::PodWeaver: config_plugins: - '@MAXMIND' finder: - ':InstallModules' - ':ExecFiles' plugins: - class: Pod::Weaver::Plugin::EnsurePod5 name: '@CorePrep/EnsurePod5' version: '4.015' - class: Pod::Weaver::Plugin::H1Nester name: '@CorePrep/H1Nester' version: '4.015' - class: Pod::Weaver::Plugin::SingleEncoding name: '@MAXMIND/SingleEncoding' version: '4.015' - class: Pod::Weaver::Plugin::Transformer name: '@MAXMIND/List' version: '4.015' - class: Pod::Weaver::Plugin::Transformer name: '@MAXMIND/Verbatim' version: '4.015' - class: Pod::Weaver::Section::Region name: '@MAXMIND/header' version: '4.015' - class: Pod::Weaver::Section::Name name: '@MAXMIND/Name' version: '4.015' - class: Pod::Weaver::Section::Version name: '@MAXMIND/Version' version: '4.015' - class: Pod::Weaver::Section::Region name: '@MAXMIND/prelude' version: '4.015' - class: Pod::Weaver::Section::Generic name: SYNOPSIS version: '4.015' - class: Pod::Weaver::Section::Generic name: DESCRIPTION version: '4.015' - class: Pod::Weaver::Section::Generic name: OVERVIEW version: '4.015' - class: Pod::Weaver::Section::Collect name: ATTRIBUTES version: '4.015' - class: Pod::Weaver::Section::Collect name: METHODS version: '4.015' - class: Pod::Weaver::Section::Collect name: FUNCTIONS version: '4.015' - class: Pod::Weaver::Section::Collect name: TYPES version: '4.015' - class: Pod::Weaver::Section::Leftovers name: '@MAXMIND/Leftovers' version: '4.015' - class: Pod::Weaver::Section::Region name: '@MAXMIND/postlude' version: '4.015' - class: Pod::Weaver::Section::GenerateSection name: '@MAXMIND/generate SUPPORT' version: '1.06' - class: Pod::Weaver::Section::AllowOverride name: '@MAXMIND/allow override SUPPORT' version: '0.05' - class: Pod::Weaver::Section::Authors name: '@MAXMIND/Authors' version: '4.015' - class: Pod::Weaver::Section::Contributors name: '@MAXMIND/Contributors' version: '0.009' - class: Pod::Weaver::Section::Legal name: '@MAXMIND/Legal' version: '4.015' - class: Pod::Weaver::Section::Region name: '@MAXMIND/footer' version: '4.015' name: '@MAXMIND/SurgicalPodWeaver' version: '0.0023' - class: Dist::Zilla::Plugin::MAXMIND::WeaverConfig name: '@MAXMIND/MAXMIND::WeaverConfig' version: '0.83' - class: Dist::Zilla::Plugin::ReadmeAnyFromPod config: Dist::Zilla::Role::FileWatcher: version: '0.006' name: '@MAXMIND/README.md in build' version: '0.163250' - class: Dist::Zilla::Plugin::GenerateFile::FromShareDir config: Dist::Zilla::Plugin::GenerateFile::FromShareDir: destination_filename: CONTRIBUTING.md dist: Dist-Zilla-PluginBundle-MAXMIND encoding: UTF-8 has_xs: '1' location: build source_filename: CONTRIBUTING.md Dist::Zilla::Role::RepoFileInjector: allow_overwrite: 1 repo_root: . version: '0.009' name: '@MAXMIND/Generate CONTRIBUTING.md' version: '0.014' - class: Dist::Zilla::Plugin::InstallGuide name: '@MAXMIND/InstallGuide' version: '1.200009' - class: Dist::Zilla::Plugin::CPANFile name: '@MAXMIND/CPANFile' version: '6.012' - class: Dist::Zilla::Plugin::PPPort name: '@MAXMIND/PPPort' version: '0.008' - class: Dist::Zilla::Plugin::MAXMIND::License name: '@MAXMIND/MAXMIND::License' version: '0.83' - class: Dist::Zilla::Plugin::CheckStrictVersion name: '@MAXMIND/CheckStrictVersion' version: '0.001' - class: Dist::Zilla::Plugin::CheckSelfDependency config: Dist::Zilla::Plugin::CheckSelfDependency: finder: - ':InstallModules' Dist::Zilla::Role::ModuleMetadata: Module::Metadata: '1.000033' version: '0.006' name: '@MAXMIND/CheckSelfDependency' version: '0.011' - class: Dist::Zilla::Plugin::CheckPrereqsIndexed name: '@MAXMIND/CheckPrereqsIndexed' version: '0.020' - class: Dist::Zilla::Plugin::MAXMIND::CheckChangesHasContent name: '@MAXMIND/MAXMIND::CheckChangesHasContent' version: '0.83' - class: Dist::Zilla::Plugin::MAXMIND::Git::CheckFor::CorrectBranch config: Dist::Zilla::Role::Git::Repo: git_version: 2.17.1 repo_root: . name: '@MAXMIND/MAXMIND::Git::CheckFor::CorrectBranch' version: '0.83' - class: Dist::Zilla::Plugin::Git::CheckFor::MergeConflicts config: Dist::Zilla::Role::Git::Repo: git_version: 2.17.1 repo_root: . name: '@MAXMIND/Git::CheckFor::MergeConflicts' version: '0.014' - class: Dist::Zilla::Plugin::MAXMIND::TidyAll name: '@MAXMIND/MAXMIND::TidyAll' version: '0.83' - class: Dist::Zilla::Plugin::UploadToCPAN name: '@MAXMIND/UploadToCPAN' version: '6.012' - class: Dist::Zilla::Plugin::Git::Check config: Dist::Zilla::Plugin::Git::Check: untracked_files: die Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - Build.PL - CONTRIBUTING.md - Changes - LICENSE - README.md - c/ppport.h - cpanfile - tidyall.ini allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: git_version: 2.17.1 repo_root: . name: '@MAXMIND/Git::Check' version: '2.045' - class: Dist::Zilla::Plugin::Git::Commit config: Dist::Zilla::Plugin::Git::Commit: add_files_in: [] commit_msg: v%v%n%n%c Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - Build.PL - CONTRIBUTING.md - Changes - LICENSE - README.md - c/ppport.h - cpanfile - tidyall.ini allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: git_version: 2.17.1 repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@MAXMIND/Commit generated files' version: '2.045' - class: Dist::Zilla::Plugin::Git::Tag config: Dist::Zilla::Plugin::Git::Tag: branch: ~ changelog: Changes signed: 0 tag: v0.300003 tag_format: v%v tag_message: v%v Dist::Zilla::Role::Git::Repo: git_version: 2.17.1 repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@MAXMIND/Git::Tag' version: '2.045' - class: Dist::Zilla::Plugin::Git::Push config: Dist::Zilla::Plugin::Git::Push: push_to: - origin remotes_must_exist: 1 Dist::Zilla::Role::Git::Repo: git_version: 2.17.1 repo_root: . name: '@MAXMIND/Git::Push' version: '2.045' - class: Dist::Zilla::Plugin::BumpVersionAfterRelease config: Dist::Zilla::Plugin::BumpVersionAfterRelease: finders: - ':ExecFiles' - ':InstallModules' global: 0 munge_makefile_pl: 1 name: '@MAXMIND/BumpVersionAfterRelease' version: '0.018' - class: Dist::Zilla::Plugin::Git::Commit config: Dist::Zilla::Plugin::Git::Commit: add_files_in: [] commit_msg: 'Bump version after release' Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - Changes - dist.ini allow_dirty_match: - (?^:.+) changelog: Changes Dist::Zilla::Role::Git::Repo: git_version: 2.17.1 repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@MAXMIND/Commit version bump' version: '2.045' - class: Dist::Zilla::Plugin::Git::Push config: Dist::Zilla::Plugin::Git::Push: push_to: - origin remotes_must_exist: 1 Dist::Zilla::Role::Git::Repo: git_version: 2.17.1 repo_root: . name: '@MAXMIND/Push version bump' version: '2.045' - class: inc::MyModuleBuild config: Dist::Zilla::Role::TestRunner: default_jobs: 1 name: =inc::MyModuleBuild version: ~ - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: develop type: requires name: DevelopRequires version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':InstallModules' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':IncModules' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':TestFiles' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':ExtraTestFiles' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':ExecFiles' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':PerlExecFiles' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':ShareFiles' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':MainModule' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':AllFiles' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':NoFiles' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: '@MAXMIND/MetaProvides::Package/AUTOVIV/:InstallModulesPM' version: '6.012' zilla: class: Dist::Zilla::Dist::Builder config: is_trial: '0' version: '6.012' x_authority: cpan:MAXMIND x_contributors: - 'Florian Ragwitz ' - 'Ilya Melamed ' - 'Jan Bieron ' - 'Narsimham Chelluri ' - 'Thomas J Mather ' - 'William Storey ' x_generated_by_perl: v5.26.1 x_serialization_backend: 'YAML::Tiny version 1.73' cpanfile100644000000000000 562313321164704 15724 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003requires "Carp" => "0"; requires "Data::Dumper::Concise" => "0"; requires "Data::IEEE754" => "0"; requires "Digest::MD5" => "0"; requires "Digest::SHA1" => "0"; requires "Encode" => "0"; requires "Exporter" => "0"; requires "IO::Handle" => "0"; requires "Math::Int128" => "0.21"; requires "Math::Int64" => "0.51"; requires "MaxMind::DB::Common" => "0.031003"; requires "MaxMind::DB::Metadata" => "0"; requires "MaxMind::DB::Reader::Decoder" => "0"; requires "MaxMind::DB::Role::Debugs" => "0"; requires "Moose" => "0"; requires "Moose::Util::TypeConstraints" => "0"; requires "MooseX::Params::Validate" => "0"; requires "MooseX::StrictConstructor" => "0"; requires "Net::Works::Network" => "0"; requires "Sereal::Decoder" => "0"; requires "Sereal::Encoder" => "3.002"; requires "Test::Deep::NoTest" => "0"; requires "XSLoader" => "0"; requires "autodie" => "0"; requires "bytes" => "0"; requires "constant" => "0"; requires "namespace::autoclean" => "0"; requires "perl" => "5.013002"; requires "strict" => "0"; requires "warnings" => "0"; on 'build' => sub { requires "Module::Build" => "0.28"; }; on 'test' => sub { requires "Data::Printer" => "0"; requires "Devel::Refcount" => "0"; requires "ExtUtils::MakeMaker" => "0"; requires "File::Spec" => "0"; requires "File::Temp" => "0"; requires "JSON" => "0"; requires "List::AllUtils" => "0"; requires "List::Util" => "0"; requires "MaxMind::DB::Reader" => "0"; requires "Net::Works::Address" => "0"; requires "Scalar::Util" => "0"; requires "Test::Bits" => "0"; requires "Test::Builder" => "0"; requires "Test::Fatal" => "0"; requires "Test::HexDifferences" => "0"; requires "Test::MaxMind::DB::Common::Data" => "0"; requires "Test::More" => "0.96"; requires "Test::Requires" => "0"; requires "Test::Warnings" => "0"; requires "lib" => "0"; requires "utf8" => "0"; }; on 'test' => sub { recommends "CPAN::Meta" => "2.120900"; }; on 'configure' => sub { requires "Module::Build" => "0.28"; }; on 'develop' => sub { requires "Code::TidyAll::Plugin::Test::Vars" => "0.02"; requires "Devel::PPPort" => "3.23"; requires "File::Temp" => "0"; requires "JSON" => "0"; requires "MaxMind::DB::Reader" => "0"; requires "Parallel::ForkManager" => "1.19"; requires "Perl::Critic" => "1.126"; requires "Perl::Tidy" => "20160302"; requires "Pod::Wordlist" => "0"; requires "Test::CPAN::Changes" => "0.19"; requires "Test::CPAN::Meta::JSON" => "0.16"; requires "Test::CleanNamespaces" => "0.15"; requires "Test::EOL" => "0"; requires "Test::Mojibake" => "0"; requires "Test::More" => "0.96"; requires "Test::NoTabs" => "0"; requires "Test::Pod" => "1.41"; requires "Test::Portability::Files" => "0"; requires "Test::Requires" => "0"; requires "Test::Spelling" => "0.12"; requires "Test::Synopsis" => "0"; requires "Test::Vars" => "0.009"; requires "Test::Version" => "2.05"; requires "lib" => "0"; requires "utf8" => "0"; }; Build.PL100644000000000000 1174713321164704 15540 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003use strict; use warnings; use lib 'inc'; use Config qw( %Config ); use Config::AutoConf; use Module::Build; if ( $^O =~ /Win32/ ) { die 'This distribution does not work on Windows platforms.' . " See the documentation for details.\n"; } my %module_build_args = ( "build_requires" => { "Module::Build" => "0.28" }, "configure_requires" => { "Module::Build" => "0.28" }, "dist_abstract" => "Create MaxMind DB database files", "dist_author" => [ "Olaf Alders ", "Greg Oschwald ", "Dave Rolsky ", "Mark Fowler " ], "dist_name" => "MaxMind-DB-Writer", "dist_version" => "0.300003", "license" => "perl", "module_name" => "MaxMind::DB::Writer", "recursive_test_files" => 1, "requires" => { "Carp" => 0, "Data::Dumper::Concise" => 0, "Data::IEEE754" => 0, "Digest::MD5" => 0, "Digest::SHA1" => 0, "Encode" => 0, "Exporter" => 0, "IO::Handle" => 0, "Math::Int128" => "0.21", "Math::Int64" => "0.51", "MaxMind::DB::Common" => "0.031003", "MaxMind::DB::Metadata" => 0, "MaxMind::DB::Reader::Decoder" => 0, "MaxMind::DB::Role::Debugs" => 0, "Moose" => 0, "Moose::Util::TypeConstraints" => 0, "MooseX::Params::Validate" => 0, "MooseX::StrictConstructor" => 0, "Net::Works::Network" => 0, "Sereal::Decoder" => 0, "Sereal::Encoder" => "3.002", "Test::Deep::NoTest" => 0, "XSLoader" => 0, "autodie" => 0, "bytes" => 0, "constant" => 0, "namespace::autoclean" => 0, "perl" => "5.013002", "strict" => 0, "warnings" => 0 }, "test_requires" => { "Data::Printer" => 0, "Devel::Refcount" => 0, "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "File::Temp" => 0, "JSON" => 0, "List::AllUtils" => 0, "List::Util" => 0, "MaxMind::DB::Reader" => 0, "Net::Works::Address" => 0, "Scalar::Util" => 0, "Test::Bits" => 0, "Test::Builder" => 0, "Test::Fatal" => 0, "Test::HexDifferences" => 0, "Test::MaxMind::DB::Common::Data" => 0, "Test::More" => "0.96", "Test::Requires" => 0, "Test::Warnings" => 0, "lib" => 0, "utf8" => 0 } ); my $mb = Module::Build->new( %module_build_args, c_source => 'c', ); $mb->extra_compiler_flags( _cc_flags($mb) ); $mb->create_build_script(); sub _cc_flags { my $mb = shift; my %unique = map { $_ => 1 } qw( -std=c99 -fms-extensions -Wall -g ), @{ $mb->extra_compiler_flags || [] }, _int64_define(), _int128_define(); return keys %unique; } sub _int64_define { my $autoconf = Config::AutoConf->new; return unless $autoconf->check_default_headers(); return '-DINT64_T' if $autoconf->check_type('int64_t'); return '-D__INT64' if $autoconf->check_type('__int64'); return '-DINT64_DI' if $autoconf->check_type('int __attribute__ ((__mode__ (DI)))'); warn <<'EOF'; It looks like your compiler doesn't support a 64-bit integer type (one of "int64_t" or "__int64"). One of these types is necessary to compile the Math::Int64 module. EOF exit 1; } sub _int128_define { my $autoconf = Config::AutoConf->new; return unless $autoconf->check_default_headers(); return '-D__INT128' if _check_type( $autoconf, '__int128' ); return '-DINT128_TI' if _check_type( $autoconf, 'int __attribute__ ((__mode__ (TI)))' ); warn <<'EOF'; It looks like your compiler doesn't support a 128-bit integer type (one of "int __attribute__ ((__mode__ (TI)))" or "__int128"). One of these types is necessary to compile the Math::Int128 module. EOF exit 1; } # This more complex check is needed in order to ferret out bugs with clang on # i386 platforms. See http://llvm.org/bugs/show_bug.cgi?id=15834 for the bug # report. This appears to be sub _check_type { my $autoconf = shift; my $type = shift; my $uint64_type = $autoconf->check_type('uint64_t') ? 'uint64_t' : $autoconf->check_type( 'unsigned int __attribute__ ((__mode__ (DI)))') ? 'unsigned int __attribute__ ((__mode__ (DI)))' : return 0; my $cache_name = $autoconf->_cache_type_name( 'type', $type ); my $check_sub = sub { my $prologue = $autoconf->_default_includes(); $prologue .= $type =~ /__mode__/ ? "typedef unsigned uint128_t __attribute__((__mode__(TI)));\n" : "typedef unsigned __int128 uint128_t;\n"; # The rand() calls are there because if we just use constants than the # compiler can optimize most of this code away. my $body = <<"EOF"; $uint64_type a = (($uint64_type)rand()) * rand(); $uint64_type b = (($uint64_type)rand()) << 24; uint128_t c = ((uint128_t)a) * b; return c > rand(); EOF my $conftest = $autoconf->lang_build_program( $prologue, $body ); return $autoconf->compile_if_else($conftest); }; return $autoconf->check_cached( $cache_name, "for $type", $check_sub ); } META.json100644000000000000 10735413321164704 15705 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003{ "abstract" : "Create MaxMind DB database files", "author" : [ "Olaf Alders ", "Greg Oschwald ", "Dave Rolsky ", "Mark Fowler " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.012, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "MaxMind-DB-Writer", "prereqs" : { "build" : { "requires" : { "Module::Build" : "0.28" } }, "configure" : { "requires" : { "Module::Build" : "0.28" } }, "develop" : { "requires" : { "Code::TidyAll::Plugin::Test::Vars" : "0.02", "Devel::PPPort" : "3.23", "File::Temp" : "0", "JSON" : "0", "MaxMind::DB::Reader" : "0", "Parallel::ForkManager" : "1.19", "Perl::Critic" : "1.126", "Perl::Tidy" : "20160302", "Pod::Wordlist" : "0", "Test::CPAN::Changes" : "0.19", "Test::CPAN::Meta::JSON" : "0.16", "Test::CleanNamespaces" : "0.15", "Test::EOL" : "0", "Test::Mojibake" : "0", "Test::More" : "0.96", "Test::NoTabs" : "0", "Test::Pod" : "1.41", "Test::Portability::Files" : "0", "Test::Requires" : "0", "Test::Spelling" : "0.12", "Test::Synopsis" : "0", "Test::Vars" : "0.009", "Test::Version" : "2.05", "lib" : "0", "utf8" : "0" } }, "runtime" : { "requires" : { "Carp" : "0", "Data::Dumper::Concise" : "0", "Data::IEEE754" : "0", "Digest::MD5" : "0", "Digest::SHA1" : "0", "Encode" : "0", "Exporter" : "0", "IO::Handle" : "0", "Math::Int128" : "0.21", "Math::Int64" : "0.51", "MaxMind::DB::Common" : "0.031003", "MaxMind::DB::Metadata" : "0", "MaxMind::DB::Reader::Decoder" : "0", "MaxMind::DB::Role::Debugs" : "0", "Moose" : "0", "Moose::Util::TypeConstraints" : "0", "MooseX::Params::Validate" : "0", "MooseX::StrictConstructor" : "0", "Net::Works::Network" : "0", "Sereal::Decoder" : "0", "Sereal::Encoder" : "3.002", "Test::Deep::NoTest" : "0", "XSLoader" : "0", "autodie" : "0", "bytes" : "0", "constant" : "0", "namespace::autoclean" : "0", "perl" : "5.013002", "strict" : "0", "warnings" : "0" } }, "test" : { "recommends" : { "CPAN::Meta" : "2.120900" }, "requires" : { "Data::Printer" : "0", "Devel::Refcount" : "0", "ExtUtils::MakeMaker" : "0", "File::Spec" : "0", "File::Temp" : "0", "JSON" : "0", "List::AllUtils" : "0", "List::Util" : "0", "MaxMind::DB::Reader" : "0", "Net::Works::Address" : "0", "Scalar::Util" : "0", "Test::Bits" : "0", "Test::Builder" : "0", "Test::Fatal" : "0", "Test::HexDifferences" : "0", "Test::MaxMind::DB::Common::Data" : "0", "Test::More" : "0.96", "Test::Requires" : "0", "Test::Warnings" : "0", "lib" : "0", "utf8" : "0" } } }, "provides" : { "MaxMind::DB::Writer" : { "file" : "lib/MaxMind/DB/Writer.pm", "version" : "0.300003" }, "MaxMind::DB::Writer::Serializer" : { "file" : "lib/MaxMind/DB/Writer/Serializer.pm", "version" : "0.300003" }, "MaxMind::DB::Writer::Tree" : { "file" : "lib/MaxMind/DB/Writer/Tree.pm", "version" : "0.300003" }, "MaxMind::DB::Writer::Tree::Processor::VisualizeTree" : { "file" : "lib/MaxMind/DB/Writer/Tree/Processor/VisualizeTree.pm", "version" : "0.300003" }, "MaxMind::DB::Writer::Util" : { "file" : "lib/MaxMind/DB/Writer/Util.pm", "version" : "0.300003" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/maxmind/MaxMind-DB-Writer-perl/issues" }, "homepage" : "http://metacpan.org/release/MaxMind-DB-Writer", "repository" : { "type" : "git", "url" : "git://github.com/maxmind/MaxMind-DB-Writer-perl.git", "web" : "https://github.com/maxmind/MaxMind-DB-Writer-perl" } }, "version" : 0.300003, "x_Dist_Zilla" : { "perl" : { "version" : "5.026001" }, "plugins" : [ { "class" : "Dist::Zilla::Plugin::Git::GatherDir", "config" : { "Dist::Zilla::Plugin::GatherDir" : { "exclude_filename" : [ "Build.PL", "CONTRIBUTING.md", "LICENSE", "README.md", "c/ppport.h", "cpanfile" ], "exclude_match" : [], "follow_symlinks" : 0, "include_dotfiles" : 0, "prefix" : "", "prune_directory" : [], "root" : "." }, "Dist::Zilla::Plugin::Git::GatherDir" : { "include_untracked" : 0 } }, "name" : "@MAXMIND/Git::GatherDir", "version" : "2.045" }, { "class" : "Dist::Zilla::Plugin::ManifestSkip", "name" : "@MAXMIND/ManifestSkip", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::License", "name" : "@MAXMIND/License", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@MAXMIND/ExecDir", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::ShareDir", "name" : "@MAXMIND/ShareDir", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::Manifest", "name" : "@MAXMIND/Manifest", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::CheckVersionIncrement", "name" : "@MAXMIND/CheckVersionIncrement", "version" : "0.121750" }, { "class" : "Dist::Zilla::Plugin::TestRelease", "name" : "@MAXMIND/TestRelease", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::ConfirmRelease", "name" : "@MAXMIND/ConfirmRelease", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::MAXMIND::VersionProvider", "name" : "@MAXMIND/MAXMIND::VersionProvider", "version" : "0.83" }, { "class" : "Dist::Zilla::Plugin::Authority", "name" : "@MAXMIND/Authority", "version" : "1.009" }, { "class" : "Dist::Zilla::Plugin::AutoPrereqs", "name" : "@MAXMIND/AutoPrereqs", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::CopyFilesFromBuild", "name" : "@MAXMIND/CopyFilesFromBuild", "version" : "0.170880" }, { "class" : "Dist::Zilla::Plugin::GitHub::Meta", "name" : "@MAXMIND/GitHub::Meta", "version" : "0.45" }, { "class" : "Dist::Zilla::Plugin::GitHub::Update", "config" : { "Dist::Zilla::Plugin::GitHub::Update" : { "metacpan" : 1 } }, "name" : "@MAXMIND/GitHub::Update", "version" : "0.45" }, { "class" : "Dist::Zilla::Plugin::MetaResources", "name" : "@MAXMIND/MetaResources", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::MetaProvides::Package", "config" : { "Dist::Zilla::Plugin::MetaProvides::Package" : { "finder_objects" : [ { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : "@MAXMIND/MetaProvides::Package/AUTOVIV/:InstallModulesPM", "version" : "6.012" } ], "include_underscores" : 0 }, "Dist::Zilla::Role::MetaProvider::Provider" : { "$Dist::Zilla::Role::MetaProvider::Provider::VERSION" : "2.002004", "inherit_missing" : 1, "inherit_version" : 1, "meta_noindex" : 1 }, "Dist::Zilla::Role::ModuleMetadata" : { "Module::Metadata" : "1.000033", "version" : "0.006" } }, "name" : "@MAXMIND/MetaProvides::Package", "version" : "2.004003" }, { "class" : "Dist::Zilla::Plugin::Meta::Contributors", "name" : "@MAXMIND/Meta::Contributors", "version" : "0.003" }, { "class" : "Dist::Zilla::Plugin::MetaConfig", "name" : "@MAXMIND/MetaConfig", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::MetaJSON", "name" : "@MAXMIND/MetaJSON", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::MetaYAML", "name" : "@MAXMIND/MetaYAML", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::NextRelease", "name" : "@MAXMIND/NextRelease", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "test", "type" : "requires" } }, "name" : "@MAXMIND/Test::More with subtest", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "develop", "type" : "requires" } }, "name" : "@MAXMIND/Modules for use with tidyall", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "develop", "type" : "requires" } }, "name" : "@MAXMIND/Test::Version which fixes https://github.com/plicease/Test-Version/issues/7", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::PromptIfStale", "config" : { "Dist::Zilla::Plugin::PromptIfStale" : { "check_all_plugins" : 0, "check_all_prereqs" : 0, "modules" : [ "Dist::Zilla::PluginBundle::MAXMIND" ], "phase" : "build", "run_under_travis" : 0, "skip" : [] } }, "name" : "@MAXMIND/Dist::Zilla::PluginBundle::MAXMIND", "version" : "0.055" }, { "class" : "Dist::Zilla::Plugin::PromptIfStale", "config" : { "Dist::Zilla::Plugin::PromptIfStale" : { "check_all_plugins" : 1, "check_all_prereqs" : 1, "modules" : [], "phase" : "release", "run_under_travis" : 0, "skip" : [ "Dist::Zilla::Plugin::MAXMIND::CheckChangesHasContent", "Dist::Zilla::Plugin::MAXMIND::Contributors", "Dist::Zilla::Plugin::MAXMIND::Git::CheckFor::CorrectBranch", "Dist::Zilla::Plugin::MAXMIND::License", "Dist::Zilla::Plugin::MAXMIND::TidyAll", "Dist::Zilla::Plugin::MAXMIND::VersionProvider", "Pod::Weaver::PluginBundle::MAXMIND" ] } }, "name" : "@MAXMIND/PromptIfStale", "version" : "0.055" }, { "class" : "Dist::Zilla::Plugin::Test::PodSpelling", "config" : { "Dist::Zilla::Plugin::Test::PodSpelling" : { "directories" : [ "bin", "lib" ], "spell_cmd" : "", "stopwords" : [ "Alders", "Alders'", "CIDR", "Eilam", "Eilam's", "GeoIP", "MAXMIND", "MAXMIND's", "MMDB", "MaxMind", "MaxMind's", "Oschwald", "Oschwald's", "PayPal", "Rolsky", "Rolsky's", "TW", "Teredo", "docs", "en", "routable", "toplevel", "uint", "zh" ], "wordlist" : "Pod::Wordlist" } }, "name" : "@MAXMIND/Test::PodSpelling", "version" : "2.007005" }, { "class" : "Dist::Zilla::Plugin::PodSyntaxTests", "name" : "@MAXMIND/PodSyntaxTests", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::RunExtraTests", "config" : { "Dist::Zilla::Role::TestRunner" : { "default_jobs" : 1 } }, "name" : "@MAXMIND/RunExtraTests", "version" : "0.029" }, { "class" : "Dist::Zilla::Plugin::MojibakeTests", "name" : "@MAXMIND/MojibakeTests", "version" : "0.8" }, { "class" : "Dist::Zilla::Plugin::Test::CleanNamespaces", "config" : { "Dist::Zilla::Plugin::Test::CleanNamespaces" : { "filename" : "xt/author/clean-namespaces.t", "skips" : [ "MaxMind::DB::Writer::Util" ] } }, "name" : "@MAXMIND/Test::CleanNamespaces", "version" : "0.006" }, { "class" : "Dist::Zilla::Plugin::Test::CPAN::Changes", "config" : { "Dist::Zilla::Plugin::Test::CPAN::Changes" : { "changelog" : "Changes" } }, "name" : "@MAXMIND/Test::CPAN::Changes", "version" : "0.012" }, { "class" : "Dist::Zilla::Plugin::Test::CPAN::Meta::JSON", "name" : "@MAXMIND/Test::CPAN::Meta::JSON", "version" : "0.004" }, { "class" : "Dist::Zilla::Plugin::Test::EOL", "config" : { "Dist::Zilla::Plugin::Test::EOL" : { "filename" : "xt/author/eol.t", "finder" : [ ":ExecFiles", ":InstallModules", ":TestFiles" ], "trailing_whitespace" : 1 } }, "name" : "@MAXMIND/Test::EOL", "version" : "0.19" }, { "class" : "Dist::Zilla::Plugin::Test::NoTabs", "config" : { "Dist::Zilla::Plugin::Test::NoTabs" : { "filename" : "xt/author/no-tabs.t", "finder" : [ ":InstallModules", ":ExecFiles", ":TestFiles" ] } }, "name" : "@MAXMIND/Test::NoTabs", "version" : "0.15" }, { "class" : "Dist::Zilla::Plugin::Test::Portability", "config" : { "Dist::Zilla::Plugin::Test::Portability" : { "options" : "" } }, "name" : "@MAXMIND/Test::Portability", "version" : "2.001000" }, { "class" : "Dist::Zilla::Plugin::Test::Synopsis", "name" : "@MAXMIND/Test::Synopsis", "version" : "2.000007" }, { "class" : "Dist::Zilla::Plugin::Test::ReportPrereqs", "name" : "@MAXMIND/Test::ReportPrereqs", "version" : "0.027" }, { "class" : "Dist::Zilla::Plugin::Test::Version", "name" : "@MAXMIND/Test::Version", "version" : "1.09" }, { "class" : "Dist::Zilla::Plugin::MAXMIND::Contributors", "name" : "@MAXMIND/MAXMIND::Contributors", "version" : "0.83" }, { "class" : "Dist::Zilla::Plugin::Git::Contributors", "config" : { "Dist::Zilla::Plugin::Git::Contributors" : { "git_version" : "2.17.1", "include_authors" : 0, "include_releaser" : 1, "order_by" : "name", "paths" : [] } }, "name" : "@MAXMIND/Git::Contributors", "version" : "0.034" }, { "class" : "Dist::Zilla::Plugin::SurgicalPodWeaver", "config" : { "Dist::Zilla::Plugin::PodWeaver" : { "config_plugins" : [ "@MAXMIND" ], "finder" : [ ":InstallModules", ":ExecFiles" ], "plugins" : [ { "class" : "Pod::Weaver::Plugin::EnsurePod5", "name" : "@CorePrep/EnsurePod5", "version" : "4.015" }, { "class" : "Pod::Weaver::Plugin::H1Nester", "name" : "@CorePrep/H1Nester", "version" : "4.015" }, { "class" : "Pod::Weaver::Plugin::SingleEncoding", "name" : "@MAXMIND/SingleEncoding", "version" : "4.015" }, { "class" : "Pod::Weaver::Plugin::Transformer", "name" : "@MAXMIND/List", "version" : "4.015" }, { "class" : "Pod::Weaver::Plugin::Transformer", "name" : "@MAXMIND/Verbatim", "version" : "4.015" }, { "class" : "Pod::Weaver::Section::Region", "name" : "@MAXMIND/header", "version" : "4.015" }, { "class" : "Pod::Weaver::Section::Name", "name" : "@MAXMIND/Name", "version" : "4.015" }, { "class" : "Pod::Weaver::Section::Version", "name" : "@MAXMIND/Version", "version" : "4.015" }, { "class" : "Pod::Weaver::Section::Region", "name" : "@MAXMIND/prelude", "version" : "4.015" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "SYNOPSIS", "version" : "4.015" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "DESCRIPTION", "version" : "4.015" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "OVERVIEW", "version" : "4.015" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "ATTRIBUTES", "version" : "4.015" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "METHODS", "version" : "4.015" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "FUNCTIONS", "version" : "4.015" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "TYPES", "version" : "4.015" }, { "class" : "Pod::Weaver::Section::Leftovers", "name" : "@MAXMIND/Leftovers", "version" : "4.015" }, { "class" : "Pod::Weaver::Section::Region", "name" : "@MAXMIND/postlude", "version" : "4.015" }, { "class" : "Pod::Weaver::Section::GenerateSection", "name" : "@MAXMIND/generate SUPPORT", "version" : "1.06" }, { "class" : "Pod::Weaver::Section::AllowOverride", "name" : "@MAXMIND/allow override SUPPORT", "version" : "0.05" }, { "class" : "Pod::Weaver::Section::Authors", "name" : "@MAXMIND/Authors", "version" : "4.015" }, { "class" : "Pod::Weaver::Section::Contributors", "name" : "@MAXMIND/Contributors", "version" : "0.009" }, { "class" : "Pod::Weaver::Section::Legal", "name" : "@MAXMIND/Legal", "version" : "4.015" }, { "class" : "Pod::Weaver::Section::Region", "name" : "@MAXMIND/footer", "version" : "4.015" } ] } }, "name" : "@MAXMIND/SurgicalPodWeaver", "version" : "0.0023" }, { "class" : "Dist::Zilla::Plugin::MAXMIND::WeaverConfig", "name" : "@MAXMIND/MAXMIND::WeaverConfig", "version" : "0.83" }, { "class" : "Dist::Zilla::Plugin::ReadmeAnyFromPod", "config" : { "Dist::Zilla::Role::FileWatcher" : { "version" : "0.006" } }, "name" : "@MAXMIND/README.md in build", "version" : "0.163250" }, { "class" : "Dist::Zilla::Plugin::GenerateFile::FromShareDir", "config" : { "Dist::Zilla::Plugin::GenerateFile::FromShareDir" : { "destination_filename" : "CONTRIBUTING.md", "dist" : "Dist-Zilla-PluginBundle-MAXMIND", "encoding" : "UTF-8", "has_xs" : 1, "location" : "build", "source_filename" : "CONTRIBUTING.md" }, "Dist::Zilla::Role::RepoFileInjector" : { "allow_overwrite" : 1, "repo_root" : ".", "version" : "0.009" } }, "name" : "@MAXMIND/Generate CONTRIBUTING.md", "version" : "0.014" }, { "class" : "Dist::Zilla::Plugin::InstallGuide", "name" : "@MAXMIND/InstallGuide", "version" : "1.200009" }, { "class" : "Dist::Zilla::Plugin::CPANFile", "name" : "@MAXMIND/CPANFile", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::PPPort", "name" : "@MAXMIND/PPPort", "version" : "0.008" }, { "class" : "Dist::Zilla::Plugin::MAXMIND::License", "name" : "@MAXMIND/MAXMIND::License", "version" : "0.83" }, { "class" : "Dist::Zilla::Plugin::CheckStrictVersion", "name" : "@MAXMIND/CheckStrictVersion", "version" : "0.001" }, { "class" : "Dist::Zilla::Plugin::CheckSelfDependency", "config" : { "Dist::Zilla::Plugin::CheckSelfDependency" : { "finder" : [ ":InstallModules" ] }, "Dist::Zilla::Role::ModuleMetadata" : { "Module::Metadata" : "1.000033", "version" : "0.006" } }, "name" : "@MAXMIND/CheckSelfDependency", "version" : "0.011" }, { "class" : "Dist::Zilla::Plugin::CheckPrereqsIndexed", "name" : "@MAXMIND/CheckPrereqsIndexed", "version" : "0.020" }, { "class" : "Dist::Zilla::Plugin::MAXMIND::CheckChangesHasContent", "name" : "@MAXMIND/MAXMIND::CheckChangesHasContent", "version" : "0.83" }, { "class" : "Dist::Zilla::Plugin::MAXMIND::Git::CheckFor::CorrectBranch", "config" : { "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.17.1", "repo_root" : "." } }, "name" : "@MAXMIND/MAXMIND::Git::CheckFor::CorrectBranch", "version" : "0.83" }, { "class" : "Dist::Zilla::Plugin::Git::CheckFor::MergeConflicts", "config" : { "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.17.1", "repo_root" : "." } }, "name" : "@MAXMIND/Git::CheckFor::MergeConflicts", "version" : "0.014" }, { "class" : "Dist::Zilla::Plugin::MAXMIND::TidyAll", "name" : "@MAXMIND/MAXMIND::TidyAll", "version" : "0.83" }, { "class" : "Dist::Zilla::Plugin::UploadToCPAN", "name" : "@MAXMIND/UploadToCPAN", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::Git::Check", "config" : { "Dist::Zilla::Plugin::Git::Check" : { "untracked_files" : "die" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "Build.PL", "CONTRIBUTING.md", "Changes", "LICENSE", "README.md", "c/ppport.h", "cpanfile", "tidyall.ini" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.17.1", "repo_root" : "." } }, "name" : "@MAXMIND/Git::Check", "version" : "2.045" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "config" : { "Dist::Zilla::Plugin::Git::Commit" : { "add_files_in" : [], "commit_msg" : "v%v%n%n%c" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "Build.PL", "CONTRIBUTING.md", "Changes", "LICENSE", "README.md", "c/ppport.h", "cpanfile", "tidyall.ini" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.17.1", "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@MAXMIND/Commit generated files", "version" : "2.045" }, { "class" : "Dist::Zilla::Plugin::Git::Tag", "config" : { "Dist::Zilla::Plugin::Git::Tag" : { "branch" : null, "changelog" : "Changes", "signed" : 0, "tag" : "v0.300003", "tag_format" : "v%v", "tag_message" : "v%v" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.17.1", "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@MAXMIND/Git::Tag", "version" : "2.045" }, { "class" : "Dist::Zilla::Plugin::Git::Push", "config" : { "Dist::Zilla::Plugin::Git::Push" : { "push_to" : [ "origin" ], "remotes_must_exist" : 1 }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.17.1", "repo_root" : "." } }, "name" : "@MAXMIND/Git::Push", "version" : "2.045" }, { "class" : "Dist::Zilla::Plugin::BumpVersionAfterRelease", "config" : { "Dist::Zilla::Plugin::BumpVersionAfterRelease" : { "finders" : [ ":ExecFiles", ":InstallModules" ], "global" : 0, "munge_makefile_pl" : 1 } }, "name" : "@MAXMIND/BumpVersionAfterRelease", "version" : "0.018" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "config" : { "Dist::Zilla::Plugin::Git::Commit" : { "add_files_in" : [], "commit_msg" : "Bump version after release" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "Changes", "dist.ini" ], "allow_dirty_match" : [ "(?^:.+)" ], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.17.1", "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@MAXMIND/Commit version bump", "version" : "2.045" }, { "class" : "Dist::Zilla::Plugin::Git::Push", "config" : { "Dist::Zilla::Plugin::Git::Push" : { "push_to" : [ "origin" ], "remotes_must_exist" : 1 }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.17.1", "repo_root" : "." } }, "name" : "@MAXMIND/Push version bump", "version" : "2.045" }, { "class" : "inc::MyModuleBuild", "config" : { "Dist::Zilla::Role::TestRunner" : { "default_jobs" : 1 } }, "name" : "=inc::MyModuleBuild", "version" : null }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "develop", "type" : "requires" } }, "name" : "DevelopRequires", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":InstallModules", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":IncModules", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":TestFiles", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExtraTestFiles", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExecFiles", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":PerlExecFiles", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ShareFiles", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":MainModule", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":AllFiles", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":NoFiles", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : "@MAXMIND/MetaProvides::Package/AUTOVIV/:InstallModulesPM", "version" : "6.012" } ], "zilla" : { "class" : "Dist::Zilla::Dist::Builder", "config" : { "is_trial" : 0 }, "version" : "6.012" } }, "x_authority" : "cpan:MAXMIND", "x_contributors" : [ "Florian Ragwitz ", "Ilya Melamed ", "Jan Bieron ", "Narsimham Chelluri ", "Thomas J Mather ", "William Storey " ], "x_generated_by_perl" : "v5.26.1", "x_serialization_backend" : "Cpanel::JSON::XS version 4.04" } README.md100644000000000000 546413321164704 15502 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003# NAME MaxMind::DB::Writer - Create MaxMind DB database files # VERSION version 0.300003 # SYNOPSIS use MaxMind::DB::Writer::Tree; my %types = ( color => 'utf8_string', dogs => [ 'array', 'utf8_string' ], size => 'uint16', ); my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 24, database_type => 'My-IP-Data', languages => ['en'], description => { en => 'My database of IP data' }, map_key_type_callback => sub { $types{ $_[0] } }, ); $tree->insert_network( '8.8.8.0/24', { color => 'blue', dogs => [ 'Fido', 'Ms. Pretty Paws' ], size => 42, }, ); open my $fh, '>:raw', '/path/to/my-ip-data.mmdb'; $tree->write_tree($fh); # DESCRIPTION This distribution contains the code necessary to write [MaxMind DB database files](http://maxmind.github.io/MaxMind-DB/). See [MaxMind::DB::Writer::Tree](https://metacpan.org/pod/MaxMind::DB::Writer::Tree) for API docs. # MAC OS X SUPPORT If you're running into install errors under Mac OS X, you may need to force a build of the 64 bit binary. For example, if you're installing via `cpanm`: ARCHFLAGS="-arch x86_64" cpanm MaxMind::DB::Writer # WINDOWS SUPPORT This distribution does not currently work on Windows. Reasonable patches for Windows support are very welcome. You will probably need to start by making [Math::Int128](https://metacpan.org/pod/Math::Int128) work on Windows, since we use that module's C API for dealing with 128-bit integers to represent IPv6 addresses numerically. # SUPPORT Please report all issues with this code using the GitHub issue tracker at [https://github.com/maxmind/MaxMind-DB-Writer-perl/issues](https://github.com/maxmind/MaxMind-DB-Writer-perl/issues). We welcome patches as pull requests against our GitHub repository at [https://github.com/maxmind/MaxMind-DB-Writer-perl](https://github.com/maxmind/MaxMind-DB-Writer-perl). Bugs may be submitted through [https://github.com/maxmind/MaxMind-DB-Writer-perl/issues](https://github.com/maxmind/MaxMind-DB-Writer-perl/issues). # AUTHORS - Olaf Alders - Greg Oschwald - Dave Rolsky - Mark Fowler # CONTRIBUTORS - Florian Ragwitz - Ilya Melamed - Jan Bieron <jbieron+github@gmail.com> - Narsimham Chelluri - Thomas J Mather - William Storey # COPYRIGHT AND LICENSE This software is copyright (c) 2018 by MaxMind, Inc. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. uthash.h100644000000000000 17023113321164704 16145 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/c/* Copyright (c) 2003-2014, Troy D. Hanson http://troydhanson.github.com/uthash/ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef UTHASH_H #define UTHASH_H #include /* memcmp,strlen */ #include /* ptrdiff_t */ #include /* exit() */ /* These macros use decltype or the earlier __typeof GNU extension. As decltype is only available in newer compilers (VS2010 or gcc 4.3+ when compiling c++ source) this code uses whatever method is needed or, for VS2008 where neither is available, uses casting workarounds. */ #if defined(_MSC_VER) /* MS compiler */ #if _MSC_VER >= 1600 && defined(__cplusplus) /* VS2010 or newer in C++ mode */ #define DECLTYPE(x) (decltype(x)) #else /* VS2008 or older (or VS2010 in C mode) */ #define NO_DECLTYPE #define DECLTYPE(x) #endif #elif defined(__BORLANDC__) || defined(__LCC__) || defined(__WATCOMC__) #define NO_DECLTYPE #define DECLTYPE(x) #else /* GNU, Sun and other compilers */ #define DECLTYPE(x) (__typeof(x)) #endif #ifdef NO_DECLTYPE #define DECLTYPE_ASSIGN(dst,src) \ do { \ char **_da_dst = (char**)(&(dst)); \ *_da_dst = (char*)(src); \ } while(0) #else #define DECLTYPE_ASSIGN(dst,src) \ do { \ (dst) = DECLTYPE(dst)(src); \ } while(0) #endif /* a number of the hash function use uint32_t which isn't defined on Pre VS2010 */ #if defined (_WIN32) #if defined(_MSC_VER) && _MSC_VER >= 1600 #include #elif defined(__WATCOMC__) #include #else typedef unsigned int uint32_t; typedef unsigned char uint8_t; #endif #else #include #endif #define UTHASH_VERSION 1.9.9 #ifndef uthash_fatal #define uthash_fatal(msg) exit(-1) /* fatal error (out of memory,etc) */ #endif #ifndef uthash_malloc #define uthash_malloc(sz) malloc(sz) /* malloc fcn */ #endif #ifndef uthash_free #define uthash_free(ptr,sz) free(ptr) /* free fcn */ #endif #ifndef uthash_noexpand_fyi #define uthash_noexpand_fyi(tbl) /* can be defined to log noexpand */ #endif #ifndef uthash_expand_fyi #define uthash_expand_fyi(tbl) /* can be defined to log expands */ #endif /* initial number of buckets */ #define HASH_INITIAL_NUM_BUCKETS 32 /* initial number of buckets */ #define HASH_INITIAL_NUM_BUCKETS_LOG2 5 /* lg2 of initial number of buckets */ #define HASH_BKT_CAPACITY_THRESH 10 /* expand when bucket count reaches */ /* calculate the element whose hash handle address is hhe */ #define ELMT_FROM_HH(tbl,hhp) ((void*)(((char*)(hhp)) - ((tbl)->hho))) #define HASH_FIND(hh,head,keyptr,keylen,out) \ do { \ out=NULL; \ if (head) { \ unsigned _hf_bkt,_hf_hashv; \ HASH_FCN(keyptr,keylen, (head)->hh.tbl->num_buckets, _hf_hashv, _hf_bkt); \ if (HASH_BLOOM_TEST((head)->hh.tbl, _hf_hashv)) { \ HASH_FIND_IN_BKT((head)->hh.tbl, hh, (head)->hh.tbl->buckets[ _hf_bkt ], \ keyptr,keylen,out); \ } \ } \ } while (0) #ifdef HASH_BLOOM #define HASH_BLOOM_BITLEN (1ULL << HASH_BLOOM) #define HASH_BLOOM_BYTELEN (HASH_BLOOM_BITLEN/8) + ((HASH_BLOOM_BITLEN%8) ? 1:0) #define HASH_BLOOM_MAKE(tbl) \ do { \ (tbl)->bloom_nbits = HASH_BLOOM; \ (tbl)->bloom_bv = (uint8_t*)uthash_malloc(HASH_BLOOM_BYTELEN); \ if (!((tbl)->bloom_bv)) { uthash_fatal( "out of memory"); } \ memset((tbl)->bloom_bv, 0, HASH_BLOOM_BYTELEN); \ (tbl)->bloom_sig = HASH_BLOOM_SIGNATURE; \ } while (0) #define HASH_BLOOM_FREE(tbl) \ do { \ uthash_free((tbl)->bloom_bv, HASH_BLOOM_BYTELEN); \ } while (0) #define HASH_BLOOM_BITSET(bv,idx) (bv[(idx)/8] |= (1U << ((idx)%8))) #define HASH_BLOOM_BITTEST(bv,idx) (bv[(idx)/8] & (1U << ((idx)%8))) #define HASH_BLOOM_ADD(tbl,hashv) \ HASH_BLOOM_BITSET((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1))) #define HASH_BLOOM_TEST(tbl,hashv) \ HASH_BLOOM_BITTEST((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1))) #else #define HASH_BLOOM_MAKE(tbl) #define HASH_BLOOM_FREE(tbl) #define HASH_BLOOM_ADD(tbl,hashv) #define HASH_BLOOM_TEST(tbl,hashv) (1) #define HASH_BLOOM_BYTELEN 0 #endif #define HASH_MAKE_TABLE(hh,head) \ do { \ (head)->hh.tbl = (UT_hash_table*)uthash_malloc( \ sizeof(UT_hash_table)); \ if (!((head)->hh.tbl)) { uthash_fatal( "out of memory"); } \ memset((head)->hh.tbl, 0, sizeof(UT_hash_table)); \ (head)->hh.tbl->tail = &((head)->hh); \ (head)->hh.tbl->num_buckets = HASH_INITIAL_NUM_BUCKETS; \ (head)->hh.tbl->log2_num_buckets = HASH_INITIAL_NUM_BUCKETS_LOG2; \ (head)->hh.tbl->hho = (char*)(&(head)->hh) - (char*)(head); \ (head)->hh.tbl->buckets = (UT_hash_bucket*)uthash_malloc( \ HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket)); \ if (! (head)->hh.tbl->buckets) { uthash_fatal( "out of memory"); } \ memset((head)->hh.tbl->buckets, 0, \ HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket)); \ HASH_BLOOM_MAKE((head)->hh.tbl); \ (head)->hh.tbl->signature = HASH_SIGNATURE; \ } while(0) #define HASH_ADD(hh,head,fieldname,keylen_in,add) \ HASH_ADD_KEYPTR(hh,head,&((add)->fieldname),keylen_in,add) #define HASH_REPLACE(hh,head,fieldname,keylen_in,add,replaced) \ do { \ replaced=NULL; \ HASH_FIND(hh,head,&((add)->fieldname),keylen_in,replaced); \ if (replaced!=NULL) { \ HASH_DELETE(hh,head,replaced); \ }; \ HASH_ADD(hh,head,fieldname,keylen_in,add); \ } while(0) #define HASH_ADD_KEYPTR(hh,head,keyptr,keylen_in,add) \ do { \ unsigned _ha_bkt; \ (add)->hh.next = NULL; \ (add)->hh.key = (char*)(keyptr); \ (add)->hh.keylen = (unsigned)(keylen_in); \ if (!(head)) { \ head = (add); \ (head)->hh.prev = NULL; \ HASH_MAKE_TABLE(hh,head); \ } else { \ (head)->hh.tbl->tail->next = (add); \ (add)->hh.prev = ELMT_FROM_HH((head)->hh.tbl, (head)->hh.tbl->tail); \ (head)->hh.tbl->tail = &((add)->hh); \ } \ (head)->hh.tbl->num_items++; \ (add)->hh.tbl = (head)->hh.tbl; \ HASH_FCN(keyptr,keylen_in, (head)->hh.tbl->num_buckets, \ (add)->hh.hashv, _ha_bkt); \ HASH_ADD_TO_BKT((head)->hh.tbl->buckets[_ha_bkt],&(add)->hh); \ HASH_BLOOM_ADD((head)->hh.tbl,(add)->hh.hashv); \ HASH_EMIT_KEY(hh,head,keyptr,keylen_in); \ HASH_FSCK(hh,head); \ } while(0) #define HASH_TO_BKT( hashv, num_bkts, bkt ) \ do { \ bkt = ((hashv) & ((num_bkts) - 1)); \ } while(0) /* delete "delptr" from the hash table. * "the usual" patch-up process for the app-order doubly-linked-list. * The use of _hd_hh_del below deserves special explanation. * These used to be expressed using (delptr) but that led to a bug * if someone used the same symbol for the head and deletee, like * HASH_DELETE(hh,users,users); * We want that to work, but by changing the head (users) below * we were forfeiting our ability to further refer to the deletee (users) * in the patch-up process. Solution: use scratch space to * copy the deletee pointer, then the latter references are via that * scratch pointer rather than through the repointed (users) symbol. */ #define HASH_DELETE(hh,head,delptr) \ do { \ struct UT_hash_handle *_hd_hh_del; \ if ( ((delptr)->hh.prev == NULL) && ((delptr)->hh.next == NULL) ) { \ uthash_free((head)->hh.tbl->buckets, \ (head)->hh.tbl->num_buckets*sizeof(struct UT_hash_bucket) ); \ HASH_BLOOM_FREE((head)->hh.tbl); \ uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \ head = NULL; \ } else { \ unsigned _hd_bkt; \ _hd_hh_del = &((delptr)->hh); \ if ((delptr) == ELMT_FROM_HH((head)->hh.tbl,(head)->hh.tbl->tail)) { \ (head)->hh.tbl->tail = \ (UT_hash_handle*)((ptrdiff_t)((delptr)->hh.prev) + \ (head)->hh.tbl->hho); \ } \ if ((delptr)->hh.prev) { \ ((UT_hash_handle*)((ptrdiff_t)((delptr)->hh.prev) + \ (head)->hh.tbl->hho))->next = (delptr)->hh.next; \ } else { \ DECLTYPE_ASSIGN(head,(delptr)->hh.next); \ } \ if (_hd_hh_del->next) { \ ((UT_hash_handle*)((ptrdiff_t)_hd_hh_del->next + \ (head)->hh.tbl->hho))->prev = \ _hd_hh_del->prev; \ } \ HASH_TO_BKT( _hd_hh_del->hashv, (head)->hh.tbl->num_buckets, _hd_bkt); \ HASH_DEL_IN_BKT(hh,(head)->hh.tbl->buckets[_hd_bkt], _hd_hh_del); \ (head)->hh.tbl->num_items--; \ } \ HASH_FSCK(hh,head); \ } while (0) /* convenience forms of HASH_FIND/HASH_ADD/HASH_DEL */ #define HASH_FIND_STR(head,findstr,out) \ HASH_FIND(hh,head,findstr,(unsigned)strlen(findstr),out) #define HASH_ADD_STR(head,strfield,add) \ HASH_ADD(hh,head,strfield[0],strlen(add->strfield),add) #define HASH_REPLACE_STR(head,strfield,add,replaced) \ HASH_REPLACE(hh,head,strfield[0],(unsigned)strlen(add->strfield),add,replaced) #define HASH_FIND_INT(head,findint,out) \ HASH_FIND(hh,head,findint,sizeof(int),out) #define HASH_ADD_INT(head,intfield,add) \ HASH_ADD(hh,head,intfield,sizeof(int),add) #define HASH_REPLACE_INT(head,intfield,add,replaced) \ HASH_REPLACE(hh,head,intfield,sizeof(int),add,replaced) #define HASH_FIND_PTR(head,findptr,out) \ HASH_FIND(hh,head,findptr,sizeof(void *),out) #define HASH_ADD_PTR(head,ptrfield,add) \ HASH_ADD(hh,head,ptrfield,sizeof(void *),add) #define HASH_REPLACE_PTR(head,ptrfield,add,replaced) \ HASH_REPLACE(hh,head,ptrfield,sizeof(void *),add,replaced) #define HASH_DEL(head,delptr) \ HASH_DELETE(hh,head,delptr) /* HASH_FSCK checks hash integrity on every add/delete when HASH_DEBUG is defined. * This is for uthash developer only; it compiles away if HASH_DEBUG isn't defined. */ #ifdef HASH_DEBUG #define HASH_OOPS(...) do { fprintf(stderr,__VA_ARGS__); exit(-1); } while (0) #define HASH_FSCK(hh,head) \ do { \ struct UT_hash_handle *_thh; \ if (head) { \ unsigned _bkt_i; \ unsigned _count; \ char *_prev; \ _count = 0; \ for( _bkt_i = 0; _bkt_i < (head)->hh.tbl->num_buckets; _bkt_i++) { \ unsigned _bkt_count = 0; \ _thh = (head)->hh.tbl->buckets[_bkt_i].hh_head; \ _prev = NULL; \ while (_thh) { \ if (_prev != (char*)(_thh->hh_prev)) { \ HASH_OOPS("invalid hh_prev %p, actual %p\n", \ _thh->hh_prev, _prev ); \ } \ _bkt_count++; \ _prev = (char*)(_thh); \ _thh = _thh->hh_next; \ } \ _count += _bkt_count; \ if ((head)->hh.tbl->buckets[_bkt_i].count != _bkt_count) { \ HASH_OOPS("invalid bucket count %u, actual %u\n", \ (head)->hh.tbl->buckets[_bkt_i].count, _bkt_count); \ } \ } \ if (_count != (head)->hh.tbl->num_items) { \ HASH_OOPS("invalid hh item count %u, actual %u\n", \ (head)->hh.tbl->num_items, _count ); \ } \ /* traverse hh in app order; check next/prev integrity, count */ \ _count = 0; \ _prev = NULL; \ _thh = &(head)->hh; \ while (_thh) { \ _count++; \ if (_prev !=(char*)(_thh->prev)) { \ HASH_OOPS("invalid prev %p, actual %p\n", \ _thh->prev, _prev ); \ } \ _prev = (char*)ELMT_FROM_HH((head)->hh.tbl, _thh); \ _thh = ( _thh->next ? (UT_hash_handle*)((char*)(_thh->next) + \ (head)->hh.tbl->hho) : NULL ); \ } \ if (_count != (head)->hh.tbl->num_items) { \ HASH_OOPS("invalid app item count %u, actual %u\n", \ (head)->hh.tbl->num_items, _count ); \ } \ } \ } while (0) #else #define HASH_FSCK(hh,head) #endif /* When compiled with -DHASH_EMIT_KEYS, length-prefixed keys are emitted to * the descriptor to which this macro is defined for tuning the hash function. * The app can #include to get the prototype for write(2). */ #ifdef HASH_EMIT_KEYS #define HASH_EMIT_KEY(hh,head,keyptr,fieldlen) \ do { \ unsigned _klen = fieldlen; \ write(HASH_EMIT_KEYS, &_klen, sizeof(_klen)); \ write(HASH_EMIT_KEYS, keyptr, fieldlen); \ } while (0) #else #define HASH_EMIT_KEY(hh,head,keyptr,fieldlen) #endif /* default to Jenkin's hash unless overridden e.g. DHASH_FUNCTION=HASH_SAX */ #ifdef HASH_FUNCTION #define HASH_FCN HASH_FUNCTION #else #define HASH_FCN HASH_JEN #endif /* The Bernstein hash function, used in Perl prior to v5.6. Note (x<<5+x)=x*33. */ #define HASH_BER(key,keylen,num_bkts,hashv,bkt) \ do { \ unsigned _hb_keylen=keylen; \ char *_hb_key=(char*)(key); \ (hashv) = 0; \ while (_hb_keylen--) { (hashv) = (((hashv) << 5) + (hashv)) + *_hb_key++; } \ bkt = (hashv) & (num_bkts-1); \ } while (0) /* SAX/FNV/OAT/JEN hash functions are macro variants of those listed at * http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx */ #define HASH_SAX(key,keylen,num_bkts,hashv,bkt) \ do { \ unsigned _sx_i; \ char *_hs_key=(char*)(key); \ hashv = 0; \ for(_sx_i=0; _sx_i < keylen; _sx_i++) \ hashv ^= (hashv << 5) + (hashv >> 2) + _hs_key[_sx_i]; \ bkt = hashv & (num_bkts-1); \ } while (0) /* FNV-1a variation */ #define HASH_FNV(key,keylen,num_bkts,hashv,bkt) \ do { \ unsigned _fn_i; \ char *_hf_key=(char*)(key); \ hashv = 2166136261UL; \ for(_fn_i=0; _fn_i < keylen; _fn_i++) { \ hashv = hashv ^ _hf_key[_fn_i]; \ hashv = hashv * 16777619; \ } \ bkt = hashv & (num_bkts-1); \ } while(0) #define HASH_OAT(key,keylen,num_bkts,hashv,bkt) \ do { \ unsigned _ho_i; \ char *_ho_key=(char*)(key); \ hashv = 0; \ for(_ho_i=0; _ho_i < keylen; _ho_i++) { \ hashv += _ho_key[_ho_i]; \ hashv += (hashv << 10); \ hashv ^= (hashv >> 6); \ } \ hashv += (hashv << 3); \ hashv ^= (hashv >> 11); \ hashv += (hashv << 15); \ bkt = hashv & (num_bkts-1); \ } while(0) #define HASH_JEN_MIX(a,b,c) \ do { \ a -= b; a -= c; a ^= ( c >> 13 ); \ b -= c; b -= a; b ^= ( a << 8 ); \ c -= a; c -= b; c ^= ( b >> 13 ); \ a -= b; a -= c; a ^= ( c >> 12 ); \ b -= c; b -= a; b ^= ( a << 16 ); \ c -= a; c -= b; c ^= ( b >> 5 ); \ a -= b; a -= c; a ^= ( c >> 3 ); \ b -= c; b -= a; b ^= ( a << 10 ); \ c -= a; c -= b; c ^= ( b >> 15 ); \ } while (0) #define HASH_JEN(key,keylen,num_bkts,hashv,bkt) \ do { \ unsigned _hj_i,_hj_j,_hj_k; \ unsigned char *_hj_key=(unsigned char*)(key); \ hashv = 0xfeedbeef; \ _hj_i = _hj_j = 0x9e3779b9; \ _hj_k = (unsigned)(keylen); \ while (_hj_k >= 12) { \ _hj_i += (_hj_key[0] + ( (unsigned)_hj_key[1] << 8 ) \ + ( (unsigned)_hj_key[2] << 16 ) \ + ( (unsigned)_hj_key[3] << 24 ) ); \ _hj_j += (_hj_key[4] + ( (unsigned)_hj_key[5] << 8 ) \ + ( (unsigned)_hj_key[6] << 16 ) \ + ( (unsigned)_hj_key[7] << 24 ) ); \ hashv += (_hj_key[8] + ( (unsigned)_hj_key[9] << 8 ) \ + ( (unsigned)_hj_key[10] << 16 ) \ + ( (unsigned)_hj_key[11] << 24 ) ); \ \ HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ \ _hj_key += 12; \ _hj_k -= 12; \ } \ hashv += keylen; \ switch ( _hj_k ) { \ case 11: hashv += ( (unsigned)_hj_key[10] << 24 ); \ case 10: hashv += ( (unsigned)_hj_key[9] << 16 ); \ case 9: hashv += ( (unsigned)_hj_key[8] << 8 ); \ case 8: _hj_j += ( (unsigned)_hj_key[7] << 24 ); \ case 7: _hj_j += ( (unsigned)_hj_key[6] << 16 ); \ case 6: _hj_j += ( (unsigned)_hj_key[5] << 8 ); \ case 5: _hj_j += _hj_key[4]; \ case 4: _hj_i += ( (unsigned)_hj_key[3] << 24 ); \ case 3: _hj_i += ( (unsigned)_hj_key[2] << 16 ); \ case 2: _hj_i += ( (unsigned)_hj_key[1] << 8 ); \ case 1: _hj_i += _hj_key[0]; \ } \ HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ bkt = hashv & (num_bkts-1); \ } while(0) /* The Paul Hsieh hash function */ #undef get16bits #if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \ || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__) #define get16bits(d) (*((const uint16_t *) (d))) #endif #if !defined (get16bits) #define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8) \ +(uint32_t)(((const uint8_t *)(d))[0]) ) #endif #define HASH_SFH(key,keylen,num_bkts,hashv,bkt) \ do { \ unsigned char *_sfh_key=(unsigned char*)(key); \ uint32_t _sfh_tmp, _sfh_len = keylen; \ \ int _sfh_rem = _sfh_len & 3; \ _sfh_len >>= 2; \ hashv = 0xcafebabe; \ \ /* Main loop */ \ for (;_sfh_len > 0; _sfh_len--) { \ hashv += get16bits (_sfh_key); \ _sfh_tmp = (uint32_t)(get16bits (_sfh_key+2)) << 11 ^ hashv; \ hashv = (hashv << 16) ^ _sfh_tmp; \ _sfh_key += 2*sizeof (uint16_t); \ hashv += hashv >> 11; \ } \ \ /* Handle end cases */ \ switch (_sfh_rem) { \ case 3: hashv += get16bits (_sfh_key); \ hashv ^= hashv << 16; \ hashv ^= (uint32_t)(_sfh_key[sizeof (uint16_t)] << 18); \ hashv += hashv >> 11; \ break; \ case 2: hashv += get16bits (_sfh_key); \ hashv ^= hashv << 11; \ hashv += hashv >> 17; \ break; \ case 1: hashv += *_sfh_key; \ hashv ^= hashv << 10; \ hashv += hashv >> 1; \ } \ \ /* Force "avalanching" of final 127 bits */ \ hashv ^= hashv << 3; \ hashv += hashv >> 5; \ hashv ^= hashv << 4; \ hashv += hashv >> 17; \ hashv ^= hashv << 25; \ hashv += hashv >> 6; \ bkt = hashv & (num_bkts-1); \ } while(0) #ifdef HASH_USING_NO_STRICT_ALIASING /* The MurmurHash exploits some CPU's (x86,x86_64) tolerance for unaligned reads. * For other types of CPU's (e.g. Sparc) an unaligned read causes a bus error. * MurmurHash uses the faster approach only on CPU's where we know it's safe. * * Note the preprocessor built-in defines can be emitted using: * * gcc -m64 -dM -E - < /dev/null (on gcc) * cc -## a.c (where a.c is a simple test file) (Sun Studio) */ #if (defined(__i386__) || defined(__x86_64__) || defined(_M_IX86)) #define MUR_GETBLOCK(p,i) p[i] #else /* non intel */ #define MUR_PLUS0_ALIGNED(p) (((unsigned long)p & 0x3) == 0) #define MUR_PLUS1_ALIGNED(p) (((unsigned long)p & 0x3) == 1) #define MUR_PLUS2_ALIGNED(p) (((unsigned long)p & 0x3) == 2) #define MUR_PLUS3_ALIGNED(p) (((unsigned long)p & 0x3) == 3) #define WP(p) ((uint32_t*)((unsigned long)(p) & ~3UL)) #if (defined(__BIG_ENDIAN__) || defined(SPARC) || defined(__ppc__) || defined(__ppc64__)) #define MUR_THREE_ONE(p) ((((*WP(p))&0x00ffffff) << 8) | (((*(WP(p)+1))&0xff000000) >> 24)) #define MUR_TWO_TWO(p) ((((*WP(p))&0x0000ffff) <<16) | (((*(WP(p)+1))&0xffff0000) >> 16)) #define MUR_ONE_THREE(p) ((((*WP(p))&0x000000ff) <<24) | (((*(WP(p)+1))&0xffffff00) >> 8)) #else /* assume little endian non-intel */ #define MUR_THREE_ONE(p) ((((*WP(p))&0xffffff00) >> 8) | (((*(WP(p)+1))&0x000000ff) << 24)) #define MUR_TWO_TWO(p) ((((*WP(p))&0xffff0000) >>16) | (((*(WP(p)+1))&0x0000ffff) << 16)) #define MUR_ONE_THREE(p) ((((*WP(p))&0xff000000) >>24) | (((*(WP(p)+1))&0x00ffffff) << 8)) #endif #define MUR_GETBLOCK(p,i) (MUR_PLUS0_ALIGNED(p) ? ((p)[i]) : \ (MUR_PLUS1_ALIGNED(p) ? MUR_THREE_ONE(p) : \ (MUR_PLUS2_ALIGNED(p) ? MUR_TWO_TWO(p) : \ MUR_ONE_THREE(p)))) #endif #define MUR_ROTL32(x,r) (((x) << (r)) | ((x) >> (32 - (r)))) #define MUR_FMIX(_h) \ do { \ _h ^= _h >> 16; \ _h *= 0x85ebca6b; \ _h ^= _h >> 13; \ _h *= 0xc2b2ae35l; \ _h ^= _h >> 16; \ } while(0) #define HASH_MUR(key,keylen,num_bkts,hashv,bkt) \ do { \ const uint8_t *_mur_data = (const uint8_t*)(key); \ const int _mur_nblocks = (keylen) / 4; \ uint32_t _mur_h1 = 0xf88D5353; \ uint32_t _mur_c1 = 0xcc9e2d51; \ uint32_t _mur_c2 = 0x1b873593; \ uint32_t _mur_k1 = 0; \ const uint8_t *_mur_tail; \ const uint32_t *_mur_blocks = (const uint32_t*)(_mur_data+_mur_nblocks*4); \ int _mur_i; \ for(_mur_i = -_mur_nblocks; _mur_i; _mur_i++) { \ _mur_k1 = MUR_GETBLOCK(_mur_blocks,_mur_i); \ _mur_k1 *= _mur_c1; \ _mur_k1 = MUR_ROTL32(_mur_k1,15); \ _mur_k1 *= _mur_c2; \ \ _mur_h1 ^= _mur_k1; \ _mur_h1 = MUR_ROTL32(_mur_h1,13); \ _mur_h1 = _mur_h1*5+0xe6546b64; \ } \ _mur_tail = (const uint8_t*)(_mur_data + _mur_nblocks*4); \ _mur_k1=0; \ switch((keylen) & 3) { \ case 3: _mur_k1 ^= _mur_tail[2] << 16; \ case 2: _mur_k1 ^= _mur_tail[1] << 8; \ case 1: _mur_k1 ^= _mur_tail[0]; \ _mur_k1 *= _mur_c1; \ _mur_k1 = MUR_ROTL32(_mur_k1,15); \ _mur_k1 *= _mur_c2; \ _mur_h1 ^= _mur_k1; \ } \ _mur_h1 ^= (keylen); \ MUR_FMIX(_mur_h1); \ hashv = _mur_h1; \ bkt = hashv & (num_bkts-1); \ } while(0) #endif /* HASH_USING_NO_STRICT_ALIASING */ /* key comparison function; return 0 if keys equal */ #define HASH_KEYCMP(a,b,len) memcmp(a,b,len) /* iterate over items in a known bucket to find desired item */ #define HASH_FIND_IN_BKT(tbl,hh,head,keyptr,keylen_in,out) \ do { \ if (head.hh_head) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,head.hh_head)); \ else out=NULL; \ while (out) { \ if ((out)->hh.keylen == keylen_in) { \ if ((HASH_KEYCMP((out)->hh.key,keyptr,keylen_in)) == 0) break; \ } \ if ((out)->hh.hh_next) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,(out)->hh.hh_next)); \ else out = NULL; \ } \ } while(0) /* add an item to a bucket */ #define HASH_ADD_TO_BKT(head,addhh) \ do { \ head.count++; \ (addhh)->hh_next = head.hh_head; \ (addhh)->hh_prev = NULL; \ if (head.hh_head) { (head).hh_head->hh_prev = (addhh); } \ (head).hh_head=addhh; \ if (head.count >= ((head.expand_mult+1) * HASH_BKT_CAPACITY_THRESH) \ && (addhh)->tbl->noexpand != 1) { \ HASH_EXPAND_BUCKETS((addhh)->tbl); \ } \ } while(0) /* remove an item from a given bucket */ #define HASH_DEL_IN_BKT(hh,head,hh_del) \ (head).count--; \ if ((head).hh_head == hh_del) { \ (head).hh_head = hh_del->hh_next; \ } \ if (hh_del->hh_prev) { \ hh_del->hh_prev->hh_next = hh_del->hh_next; \ } \ if (hh_del->hh_next) { \ hh_del->hh_next->hh_prev = hh_del->hh_prev; \ } /* Bucket expansion has the effect of doubling the number of buckets * and redistributing the items into the new buckets. Ideally the * items will distribute more or less evenly into the new buckets * (the extent to which this is true is a measure of the quality of * the hash function as it applies to the key domain). * * With the items distributed into more buckets, the chain length * (item count) in each bucket is reduced. Thus by expanding buckets * the hash keeps a bound on the chain length. This bounded chain * length is the essence of how a hash provides constant time lookup. * * The calculation of tbl->ideal_chain_maxlen below deserves some * explanation. First, keep in mind that we're calculating the ideal * maximum chain length based on the *new* (doubled) bucket count. * In fractions this is just n/b (n=number of items,b=new num buckets). * Since the ideal chain length is an integer, we want to calculate * ceil(n/b). We don't depend on floating point arithmetic in this * hash, so to calculate ceil(n/b) with integers we could write * * ceil(n/b) = (n/b) + ((n%b)?1:0) * * and in fact a previous version of this hash did just that. * But now we have improved things a bit by recognizing that b is * always a power of two. We keep its base 2 log handy (call it lb), * so now we can write this with a bit shift and logical AND: * * ceil(n/b) = (n>>lb) + ( (n & (b-1)) ? 1:0) * */ #define HASH_EXPAND_BUCKETS(tbl) \ do { \ unsigned _he_bkt; \ unsigned _he_bkt_i; \ struct UT_hash_handle *_he_thh, *_he_hh_nxt; \ UT_hash_bucket *_he_new_buckets, *_he_newbkt; \ _he_new_buckets = (UT_hash_bucket*)uthash_malloc( \ 2 * tbl->num_buckets * sizeof(struct UT_hash_bucket)); \ if (!_he_new_buckets) { uthash_fatal( "out of memory"); } \ memset(_he_new_buckets, 0, \ 2 * tbl->num_buckets * sizeof(struct UT_hash_bucket)); \ tbl->ideal_chain_maxlen = \ (tbl->num_items >> (tbl->log2_num_buckets+1)) + \ ((tbl->num_items & ((tbl->num_buckets*2)-1)) ? 1 : 0); \ tbl->nonideal_items = 0; \ for(_he_bkt_i = 0; _he_bkt_i < tbl->num_buckets; _he_bkt_i++) \ { \ _he_thh = tbl->buckets[ _he_bkt_i ].hh_head; \ while (_he_thh) { \ _he_hh_nxt = _he_thh->hh_next; \ HASH_TO_BKT( _he_thh->hashv, tbl->num_buckets*2, _he_bkt); \ _he_newbkt = &(_he_new_buckets[ _he_bkt ]); \ if (++(_he_newbkt->count) > tbl->ideal_chain_maxlen) { \ tbl->nonideal_items++; \ _he_newbkt->expand_mult = _he_newbkt->count / \ tbl->ideal_chain_maxlen; \ } \ _he_thh->hh_prev = NULL; \ _he_thh->hh_next = _he_newbkt->hh_head; \ if (_he_newbkt->hh_head) _he_newbkt->hh_head->hh_prev = \ _he_thh; \ _he_newbkt->hh_head = _he_thh; \ _he_thh = _he_hh_nxt; \ } \ } \ uthash_free( tbl->buckets, tbl->num_buckets*sizeof(struct UT_hash_bucket) ); \ tbl->num_buckets *= 2; \ tbl->log2_num_buckets++; \ tbl->buckets = _he_new_buckets; \ tbl->ineff_expands = (tbl->nonideal_items > (tbl->num_items >> 1)) ? \ (tbl->ineff_expands+1) : 0; \ if (tbl->ineff_expands > 1) { \ tbl->noexpand=1; \ uthash_noexpand_fyi(tbl); \ } \ uthash_expand_fyi(tbl); \ } while(0) /* This is an adaptation of Simon Tatham's O(n log(n)) mergesort */ /* Note that HASH_SORT assumes the hash handle name to be hh. * HASH_SRT was added to allow the hash handle name to be passed in. */ #define HASH_SORT(head,cmpfcn) HASH_SRT(hh,head,cmpfcn) #define HASH_SRT(hh,head,cmpfcn) \ do { \ unsigned _hs_i; \ unsigned _hs_looping,_hs_nmerges,_hs_insize,_hs_psize,_hs_qsize; \ struct UT_hash_handle *_hs_p, *_hs_q, *_hs_e, *_hs_list, *_hs_tail; \ if (head) { \ _hs_insize = 1; \ _hs_looping = 1; \ _hs_list = &((head)->hh); \ while (_hs_looping) { \ _hs_p = _hs_list; \ _hs_list = NULL; \ _hs_tail = NULL; \ _hs_nmerges = 0; \ while (_hs_p) { \ _hs_nmerges++; \ _hs_q = _hs_p; \ _hs_psize = 0; \ for ( _hs_i = 0; _hs_i < _hs_insize; _hs_i++ ) { \ _hs_psize++; \ _hs_q = (UT_hash_handle*)((_hs_q->next) ? \ ((void*)((char*)(_hs_q->next) + \ (head)->hh.tbl->hho)) : NULL); \ if (! (_hs_q) ) break; \ } \ _hs_qsize = _hs_insize; \ while ((_hs_psize > 0) || ((_hs_qsize > 0) && _hs_q )) { \ if (_hs_psize == 0) { \ _hs_e = _hs_q; \ _hs_q = (UT_hash_handle*)((_hs_q->next) ? \ ((void*)((char*)(_hs_q->next) + \ (head)->hh.tbl->hho)) : NULL); \ _hs_qsize--; \ } else if ( (_hs_qsize == 0) || !(_hs_q) ) { \ _hs_e = _hs_p; \ if (_hs_p){ \ _hs_p = (UT_hash_handle*)((_hs_p->next) ? \ ((void*)((char*)(_hs_p->next) + \ (head)->hh.tbl->hho)) : NULL); \ } \ _hs_psize--; \ } else if (( \ cmpfcn(DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl,_hs_p)), \ DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl,_hs_q))) \ ) <= 0) { \ _hs_e = _hs_p; \ if (_hs_p){ \ _hs_p = (UT_hash_handle*)((_hs_p->next) ? \ ((void*)((char*)(_hs_p->next) + \ (head)->hh.tbl->hho)) : NULL); \ } \ _hs_psize--; \ } else { \ _hs_e = _hs_q; \ _hs_q = (UT_hash_handle*)((_hs_q->next) ? \ ((void*)((char*)(_hs_q->next) + \ (head)->hh.tbl->hho)) : NULL); \ _hs_qsize--; \ } \ if ( _hs_tail ) { \ _hs_tail->next = ((_hs_e) ? \ ELMT_FROM_HH((head)->hh.tbl,_hs_e) : NULL); \ } else { \ _hs_list = _hs_e; \ } \ if (_hs_e) { \ _hs_e->prev = ((_hs_tail) ? \ ELMT_FROM_HH((head)->hh.tbl,_hs_tail) : NULL); \ } \ _hs_tail = _hs_e; \ } \ _hs_p = _hs_q; \ } \ if (_hs_tail){ \ _hs_tail->next = NULL; \ } \ if ( _hs_nmerges <= 1 ) { \ _hs_looping=0; \ (head)->hh.tbl->tail = _hs_tail; \ DECLTYPE_ASSIGN(head,ELMT_FROM_HH((head)->hh.tbl, _hs_list)); \ } \ _hs_insize *= 2; \ } \ HASH_FSCK(hh,head); \ } \ } while (0) /* This function selects items from one hash into another hash. * The end result is that the selected items have dual presence * in both hashes. There is no copy of the items made; rather * they are added into the new hash through a secondary hash * hash handle that must be present in the structure. */ #define HASH_SELECT(hh_dst, dst, hh_src, src, cond) \ do { \ unsigned _src_bkt, _dst_bkt; \ void *_last_elt=NULL, *_elt; \ UT_hash_handle *_src_hh, *_dst_hh, *_last_elt_hh=NULL; \ ptrdiff_t _dst_hho = ((char*)(&(dst)->hh_dst) - (char*)(dst)); \ if (src) { \ for(_src_bkt=0; _src_bkt < (src)->hh_src.tbl->num_buckets; _src_bkt++) { \ for(_src_hh = (src)->hh_src.tbl->buckets[_src_bkt].hh_head; \ _src_hh; \ _src_hh = _src_hh->hh_next) { \ _elt = ELMT_FROM_HH((src)->hh_src.tbl, _src_hh); \ if (cond(_elt)) { \ _dst_hh = (UT_hash_handle*)(((char*)_elt) + _dst_hho); \ _dst_hh->key = _src_hh->key; \ _dst_hh->keylen = _src_hh->keylen; \ _dst_hh->hashv = _src_hh->hashv; \ _dst_hh->prev = _last_elt; \ _dst_hh->next = NULL; \ if (_last_elt_hh) { _last_elt_hh->next = _elt; } \ if (!dst) { \ DECLTYPE_ASSIGN(dst,_elt); \ HASH_MAKE_TABLE(hh_dst,dst); \ } else { \ _dst_hh->tbl = (dst)->hh_dst.tbl; \ } \ HASH_TO_BKT(_dst_hh->hashv, _dst_hh->tbl->num_buckets, _dst_bkt); \ HASH_ADD_TO_BKT(_dst_hh->tbl->buckets[_dst_bkt],_dst_hh); \ (dst)->hh_dst.tbl->num_items++; \ _last_elt = _elt; \ _last_elt_hh = _dst_hh; \ } \ } \ } \ } \ HASH_FSCK(hh_dst,dst); \ } while (0) #define HASH_CLEAR(hh,head) \ do { \ if (head) { \ uthash_free((head)->hh.tbl->buckets, \ (head)->hh.tbl->num_buckets*sizeof(struct UT_hash_bucket)); \ HASH_BLOOM_FREE((head)->hh.tbl); \ uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \ (head)=NULL; \ } \ } while(0) #define HASH_OVERHEAD(hh,head) \ (size_t)((((head)->hh.tbl->num_items * sizeof(UT_hash_handle)) + \ ((head)->hh.tbl->num_buckets * sizeof(UT_hash_bucket)) + \ (sizeof(UT_hash_table)) + \ (HASH_BLOOM_BYTELEN))) #ifdef NO_DECLTYPE #define HASH_ITER(hh,head,el,tmp) \ for((el)=(head), (*(char**)(&(tmp)))=(char*)((head)?(head)->hh.next:NULL); \ el; (el)=(tmp),(*(char**)(&(tmp)))=(char*)((tmp)?(tmp)->hh.next:NULL)) #else #define HASH_ITER(hh,head,el,tmp) \ for((el)=(head),(tmp)=DECLTYPE(el)((head)?(head)->hh.next:NULL); \ el; (el)=(tmp),(tmp)=DECLTYPE(el)((tmp)?(tmp)->hh.next:NULL)) #endif /* obtain a count of items in the hash */ #define HASH_COUNT(head) HASH_CNT(hh,head) #define HASH_CNT(hh,head) ((head)?((head)->hh.tbl->num_items):0) typedef struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned count; /* expand_mult is normally set to 0. In this situation, the max chain length * threshold is enforced at its default value, HASH_BKT_CAPACITY_THRESH. (If * the bucket's chain exceeds this length, bucket expansion is triggered). * However, setting expand_mult to a non-zero value delays bucket expansion * (that would be triggered by additions to this particular bucket) * until its chain length reaches a *multiple* of HASH_BKT_CAPACITY_THRESH. * (The multiplier is simply expand_mult+1). The whole idea of this * multiplier is to reduce bucket expansions, since they are expensive, in * situations where we know that a particular bucket tends to be overused. * It is better to let its chain length grow to a longer yet-still-bounded * value, than to do an O(n) bucket expansion too often. */ unsigned expand_mult; } UT_hash_bucket; /* random signature used only to find hash tables in external analysis */ #define HASH_SIGNATURE 0xa0111fe1 #define HASH_BLOOM_SIGNATURE 0xb12220f2 typedef struct UT_hash_table { UT_hash_bucket *buckets; unsigned num_buckets, log2_num_buckets; unsigned num_items; struct UT_hash_handle *tail; /* tail hh in app order, for fast append */ ptrdiff_t hho; /* hash handle offset (byte pos of hash handle in element */ /* in an ideal situation (all buckets used equally), no bucket would have * more than ceil(#items/#buckets) items. that's the ideal chain length. */ unsigned ideal_chain_maxlen; /* nonideal_items is the number of items in the hash whose chain position * exceeds the ideal chain maxlen. these items pay the penalty for an uneven * hash distribution; reaching them in a chain traversal takes >ideal steps */ unsigned nonideal_items; /* ineffective expands occur when a bucket doubling was performed, but * afterward, more than half the items in the hash had nonideal chain * positions. If this happens on two consecutive expansions we inhibit any * further expansion, as it's not helping; this happens when the hash * function isn't a good fit for the key domain. When expansion is inhibited * the hash will still work, albeit no longer in constant time. */ unsigned ineff_expands, noexpand; uint32_t signature; /* used only to find hash tables in external analysis */ #ifdef HASH_BLOOM uint32_t bloom_sig; /* used only to test bloom exists in external analysis */ uint8_t *bloom_bv; char bloom_nbits; #endif } UT_hash_table; typedef struct UT_hash_handle { struct UT_hash_table *tbl; void *prev; /* prev element in app order */ void *next; /* next element in app order */ struct UT_hash_handle *hh_prev; /* previous hh in bucket order */ struct UT_hash_handle *hh_next; /* next hh in bucket order */ void *key; /* ptr to enclosing struct's key */ unsigned keylen; /* enclosing struct's key len */ unsigned hashv; /* result of hash-fcn(key) */ } UT_hash_handle; #endif /* UTHASH_H */ perltidyrc100644000000000000 33013321164704 16272 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003--blank-lines-before-packages=0 --iterations=2 --no-outdent-long-comments -b -bar -boc -ci=4 -i=4 -l=78 -nolq -se -wbb="% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x=" ppport.h100644000000000000 60672513321164704 16211 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/c#if 0 <<'SKIP'; #endif /* ---------------------------------------------------------------------- c/ppport.h -- Perl/Pollution/Portability Version 3.42 Automatically created by Devel::PPPort running under perl 5.026001. Do NOT edit this file directly! -- Edit PPPort_pm.PL and the includes in parts/inc/ instead. Use 'perldoc c/ppport.h' to view the documentation below. ---------------------------------------------------------------------- SKIP =pod =head1 NAME c/ppport.h - Perl/Pollution/Portability version 3.42 =head1 SYNOPSIS perl c/ppport.h [options] [source files] Searches current directory for files if no [source files] are given --help show short help --version show version --patch=file write one patch file with changes --copy=suffix write changed copies with suffix --diff=program use diff program and options --compat-version=version provide compatibility with Perl version --cplusplus accept C++ comments --quiet don't output anything except fatal errors --nodiag don't show diagnostics --nohints don't show hints --nochanges don't suggest changes --nofilter don't filter input files --strip strip all script and doc functionality from c/ppport.h --list-provided list provided API --list-unsupported list unsupported API --api-info=name show Perl API portability information =head1 COMPATIBILITY This version of F is designed to support operation with Perl installations back to 5.003, and has been tested up to 5.20. =head1 OPTIONS =head2 --help Display a brief usage summary. =head2 --version Display the version of F. =head2 --patch=I If this option is given, a single patch file will be created if any changes are suggested. This requires a working diff program to be installed on your system. =head2 --copy=I If this option is given, a copy of each file will be saved with the given suffix that contains the suggested changes. This does not require any external programs. Note that this does not automagically add a dot between the original filename and the suffix. If you want the dot, you have to include it in the option argument. If neither C<--patch> or C<--copy> are given, the default is to simply print the diffs for each file. This requires either C or a C program to be installed. =head2 --diff=I Manually set the diff program and options to use. The default is to use C, when installed, and output unified context diffs. =head2 --compat-version=I Tell F to check for compatibility with the given Perl version. The default is to check for compatibility with Perl version 5.003. You can use this option to reduce the output of F if you intend to be backward compatible only down to a certain Perl version. =head2 --cplusplus Usually, F will detect C++ style comments and replace them with C style comments for portability reasons. Using this option instructs F to leave C++ comments untouched. =head2 --quiet Be quiet. Don't print anything except fatal errors. =head2 --nodiag Don't output any diagnostic messages. Only portability alerts will be printed. =head2 --nohints Don't output any hints. Hints often contain useful portability notes. Warnings will still be displayed. =head2 --nochanges Don't suggest any changes. Only give diagnostic output and hints unless these are also deactivated. =head2 --nofilter Don't filter the list of input files. By default, files not looking like source code (i.e. not *.xs, *.c, *.cc, *.cpp or *.h) are skipped. =head2 --strip Strip all script and documentation functionality from F. This reduces the size of F dramatically and may be useful if you want to include F in smaller modules without increasing their distribution size too much. The stripped F will have a C<--unstrip> option that allows you to undo the stripping, but only if an appropriate C module is installed. =head2 --list-provided Lists the API elements for which compatibility is provided by F. Also lists if it must be explicitly requested, if it has dependencies, and if there are hints or warnings for it. =head2 --list-unsupported Lists the API elements that are known not to be supported by F and below which version of Perl they probably won't be available or work. =head2 --api-info=I Show portability information for API elements matching I. If I is surrounded by slashes, it is interpreted as a regular expression. =head1 DESCRIPTION In order for a Perl extension (XS) module to be as portable as possible across differing versions of Perl itself, certain steps need to be taken. =over 4 =item * Including this header is the first major one. This alone will give you access to a large part of the Perl API that hasn't been available in earlier Perl releases. Use perl c/ppport.h --list-provided to see which API elements are provided by c/ppport.h. =item * You should avoid using deprecated parts of the API. For example, using global Perl variables without the C prefix is deprecated. Also, some API functions used to have a C prefix. Using this form is also deprecated. You can safely use the supported API, as F will provide wrappers for older Perl versions. =item * If you use one of a few functions or variables that were not present in earlier versions of Perl, and that can't be provided using a macro, you have to explicitly request support for these functions by adding one or more C<#define>s in your source code before the inclusion of F. These functions or variables will be marked C in the list shown by C<--list-provided>. Depending on whether you module has a single or multiple files that use such functions or variables, you want either C or global variants. For a C function or variable (used only in a single source file), use: #define NEED_function #define NEED_variable For a global function or variable (used in multiple source files), use: #define NEED_function_GLOBAL #define NEED_variable_GLOBAL Note that you mustn't have more than one global request for the same function or variable in your project. Function / Variable Static Request Global Request ----------------------------------------------------------------------------------------- PL_parser NEED_PL_parser NEED_PL_parser_GLOBAL PL_signals NEED_PL_signals NEED_PL_signals_GLOBAL SvRX() NEED_SvRX NEED_SvRX_GLOBAL caller_cx() NEED_caller_cx NEED_caller_cx_GLOBAL croak_xs_usage() NEED_croak_xs_usage NEED_croak_xs_usage_GLOBAL die_sv() NEED_die_sv NEED_die_sv_GLOBAL eval_pv() NEED_eval_pv NEED_eval_pv_GLOBAL grok_bin() NEED_grok_bin NEED_grok_bin_GLOBAL grok_hex() NEED_grok_hex NEED_grok_hex_GLOBAL grok_number() NEED_grok_number NEED_grok_number_GLOBAL grok_numeric_radix() NEED_grok_numeric_radix NEED_grok_numeric_radix_GLOBAL grok_oct() NEED_grok_oct NEED_grok_oct_GLOBAL gv_fetchpvn_flags() NEED_gv_fetchpvn_flags NEED_gv_fetchpvn_flags_GLOBAL load_module() NEED_load_module NEED_load_module_GLOBAL mess() NEED_mess NEED_mess_GLOBAL mess_nocontext() NEED_mess_nocontext NEED_mess_nocontext_GLOBAL mess_sv() NEED_mess_sv NEED_mess_sv_GLOBAL mg_findext() NEED_mg_findext NEED_mg_findext_GLOBAL my_snprintf() NEED_my_snprintf NEED_my_snprintf_GLOBAL my_sprintf() NEED_my_sprintf NEED_my_sprintf_GLOBAL my_strlcat() NEED_my_strlcat NEED_my_strlcat_GLOBAL my_strlcpy() NEED_my_strlcpy NEED_my_strlcpy_GLOBAL newCONSTSUB() NEED_newCONSTSUB NEED_newCONSTSUB_GLOBAL newRV_noinc() NEED_newRV_noinc NEED_newRV_noinc_GLOBAL newSV_type() NEED_newSV_type NEED_newSV_type_GLOBAL newSVpvn_flags() NEED_newSVpvn_flags NEED_newSVpvn_flags_GLOBAL newSVpvn_share() NEED_newSVpvn_share NEED_newSVpvn_share_GLOBAL pv_display() NEED_pv_display NEED_pv_display_GLOBAL pv_escape() NEED_pv_escape NEED_pv_escape_GLOBAL pv_pretty() NEED_pv_pretty NEED_pv_pretty_GLOBAL sv_2pv_flags() NEED_sv_2pv_flags NEED_sv_2pv_flags_GLOBAL sv_2pvbyte() NEED_sv_2pvbyte NEED_sv_2pvbyte_GLOBAL sv_catpvf_mg() NEED_sv_catpvf_mg NEED_sv_catpvf_mg_GLOBAL sv_catpvf_mg_nocontext() NEED_sv_catpvf_mg_nocontext NEED_sv_catpvf_mg_nocontext_GLOBAL sv_pvn_force_flags() NEED_sv_pvn_force_flags NEED_sv_pvn_force_flags_GLOBAL sv_setpvf_mg() NEED_sv_setpvf_mg NEED_sv_setpvf_mg_GLOBAL sv_setpvf_mg_nocontext() NEED_sv_setpvf_mg_nocontext NEED_sv_setpvf_mg_nocontext_GLOBAL sv_unmagicext() NEED_sv_unmagicext NEED_sv_unmagicext_GLOBAL vload_module() NEED_vload_module NEED_vload_module_GLOBAL vmess() NEED_vmess NEED_vmess_GLOBAL vnewSVpvf() NEED_vnewSVpvf NEED_vnewSVpvf_GLOBAL warner() NEED_warner NEED_warner_GLOBAL To avoid namespace conflicts, you can change the namespace of the explicitly exported functions / variables using the C macro. Just C<#define> the macro before including C: #define DPPP_NAMESPACE MyOwnNamespace_ #include "c/ppport.h" The default namespace is C. =back The good thing is that most of the above can be checked by running F on your source code. See the next section for details. =head1 EXAMPLES To verify whether F is needed for your module, whether you should make any changes to your code, and whether any special defines should be used, F can be run as a Perl script to check your source code. Simply say: perl c/ppport.h The result will usually be a list of patches suggesting changes that should at least be acceptable, if not necessarily the most efficient solution, or a fix for all possible problems. If you know that your XS module uses features only available in newer Perl releases, if you're aware that it uses C++ comments, and if you want all suggestions as a single patch file, you could use something like this: perl c/ppport.h --compat-version=5.6.0 --cplusplus --patch=test.diff If you only want your code to be scanned without any suggestions for changes, use: perl c/ppport.h --nochanges You can specify a different C program or options, using the C<--diff> option: perl c/ppport.h --diff='diff -C 10' This would output context diffs with 10 lines of context. If you want to create patched copies of your files instead, use: perl c/ppport.h --copy=.new To display portability information for the C function, use: perl c/ppport.h --api-info=newSVpvn Since the argument to C<--api-info> can be a regular expression, you can use perl c/ppport.h --api-info=/_nomg$/ to display portability information for all C<_nomg> functions or perl c/ppport.h --api-info=/./ to display information for all known API elements. =head1 BUGS If this version of F is causing failure during the compilation of this module, please check if newer versions of either this module or C are available on CPAN before sending a bug report. If F was generated using the latest version of C and is causing failure of this module, please send a bug report to L. Please include the following information: =over 4 =item 1. The complete output from running "perl -V" =item 2. This file. =item 3. The name and version of the module you were trying to build. =item 4. A full log of the build that failed. =item 5. Any other information that you think could be relevant. =back For the latest version of this code, please get the C module from CPAN. =head1 COPYRIGHT Version 3.x, Copyright (c) 2004-2013, Marcus Holland-Moritz. Version 2.x, Copyright (C) 2001, Paul Marquess. Version 1.x, Copyright (C) 1999, Kenneth Albanowski. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO See L. =cut use strict; # Disable broken TRIE-optimization BEGIN { eval '${^RE_TRIE_MAXBUF} = -1' if "$]" >= 5.009004 && "$]" <= 5.009005 } my $VERSION = 3.42; my %opt = ( quiet => 0, diag => 1, hints => 1, changes => 1, cplusplus => 0, filter => 1, strip => 0, version => 0, ); my($ppport) = $0 =~ /([\w.]+)$/; my $LF = '(?:\r\n|[\r\n])'; # line feed my $HS = "[ \t]"; # horizontal whitespace # Never use C comments in this file! my $ccs = '/'.'*'; my $cce = '*'.'/'; my $rccs = quotemeta $ccs; my $rcce = quotemeta $cce; eval { require Getopt::Long; Getopt::Long::GetOptions(\%opt, qw( help quiet diag! filter! hints! changes! cplusplus strip version patch=s copy=s diff=s compat-version=s list-provided list-unsupported api-info=s )) or usage(); }; if ($@ and grep /^-/, @ARGV) { usage() if "@ARGV" =~ /^--?h(?:elp)?$/; die "Getopt::Long not found. Please don't use any options.\n"; } if ($opt{version}) { print "This is $0 $VERSION.\n"; exit 0; } usage() if $opt{help}; strip() if $opt{strip}; if (exists $opt{'compat-version'}) { my($r,$v,$s) = eval { parse_version($opt{'compat-version'}) }; if ($@) { die "Invalid version number format: '$opt{'compat-version'}'\n"; } die "Only Perl 5 is supported\n" if $r != 5; die "Invalid version number: $opt{'compat-version'}\n" if $v >= 1000 || $s >= 1000; $opt{'compat-version'} = sprintf "%d.%03d%03d", $r, $v, $s; } else { $opt{'compat-version'} = 5; } my %API = map { /^(\w+)\|([^|]*)\|([^|]*)\|(\w*)$/ ? ( $1 => { ($2 ? ( base => $2 ) : ()), ($3 ? ( todo => $3 ) : ()), (index($4, 'v') >= 0 ? ( varargs => 1 ) : ()), (index($4, 'p') >= 0 ? ( provided => 1 ) : ()), (index($4, 'n') >= 0 ? ( nothxarg => 1 ) : ()), } ) : die "invalid spec: $_" } qw( AvFILLp|5.004050||p AvFILL||| BhkDISABLE||5.024000| BhkENABLE||5.024000| BhkENTRY_set||5.024000| BhkENTRY||| BhkFLAGS||| CALL_BLOCK_HOOKS||| CLASS|||n CPERLscope|5.005000||p CX_CURPAD_SAVE||| CX_CURPAD_SV||| C_ARRAY_END|5.013002||p C_ARRAY_LENGTH|5.008001||p CopFILEAV|5.006000||p CopFILEGV_set|5.006000||p CopFILEGV|5.006000||p CopFILESV|5.006000||p CopFILE_set|5.006000||p CopFILE|5.006000||p CopSTASHPV_set|5.006000||p CopSTASHPV|5.006000||p CopSTASH_eq|5.006000||p CopSTASH_set|5.006000||p CopSTASH|5.006000||p CopyD|5.009002|5.004050|p Copy||| CvPADLIST||5.008001| CvSTASH||| CvWEAKOUTSIDE||| DECLARATION_FOR_LC_NUMERIC_MANIPULATION||5.021010|n DEFSV_set|5.010001||p DEFSV|5.004050||p DO_UTF8||5.006000| END_EXTERN_C|5.005000||p ENTER||| ERRSV|5.004050||p EXTEND||| EXTERN_C|5.005000||p F0convert|||n FREETMPS||| GIMME_V||5.004000|n GIMME|||n GROK_NUMERIC_RADIX|5.007002||p G_ARRAY||| G_DISCARD||| G_EVAL||| G_METHOD|5.006001||p G_NOARGS||| G_SCALAR||| G_VOID||5.004000| GetVars||| GvAV||| GvCV||| GvHV||| GvSV||| Gv_AMupdate||5.011000| HEf_SVKEY|5.003070||p HeHASH||5.003070| HeKEY||5.003070| HeKLEN||5.003070| HePV||5.004000| HeSVKEY_force||5.003070| HeSVKEY_set||5.004000| HeSVKEY||5.003070| HeUTF8|5.010001|5.008000|p HeVAL||5.003070| HvENAMELEN||5.015004| HvENAMEUTF8||5.015004| HvENAME||5.013007| HvNAMELEN_get|5.009003||p HvNAMELEN||5.015004| HvNAMEUTF8||5.015004| HvNAME_get|5.009003||p HvNAME||| INT2PTR|5.006000||p IN_LOCALE_COMPILETIME|5.007002||p IN_LOCALE_RUNTIME|5.007002||p IN_LOCALE|5.007002||p IN_PERL_COMPILETIME|5.008001||p IS_NUMBER_GREATER_THAN_UV_MAX|5.007002||p IS_NUMBER_INFINITY|5.007002||p IS_NUMBER_IN_UV|5.007002||p IS_NUMBER_NAN|5.007003||p IS_NUMBER_NEG|5.007002||p IS_NUMBER_NOT_INT|5.007002||p IVSIZE|5.006000||p IVTYPE|5.006000||p IVdf|5.006000||p LEAVE||| LINKLIST||5.013006| LVRET||| MARK||| MULTICALL||5.024000| MUTABLE_PTR|5.010001||p MUTABLE_SV|5.010001||p MY_CXT_CLONE|5.009002||p MY_CXT_INIT|5.007003||p MY_CXT|5.007003||p MoveD|5.009002|5.004050|p Move||| NOOP|5.005000||p NUM2PTR|5.006000||p NVTYPE|5.006000||p NVef|5.006001||p NVff|5.006001||p NVgf|5.006001||p Newxc|5.009003||p Newxz|5.009003||p Newx|5.009003||p Nullav||| Nullch||| Nullcv||| Nullhv||| Nullsv||| OP_CLASS||5.013007| OP_DESC||5.007003| OP_NAME||5.007003| OP_TYPE_IS_OR_WAS||5.019010| OP_TYPE_IS||5.019007| ORIGMARK||| OpHAS_SIBLING|5.021007||p OpLASTSIB_set|5.021011||p OpMAYBESIB_set|5.021011||p OpMORESIB_set|5.021011||p OpSIBLING|5.021007||p PAD_BASE_SV||| PAD_CLONE_VARS||| PAD_COMPNAME_FLAGS||| PAD_COMPNAME_GEN_set||| PAD_COMPNAME_GEN||| PAD_COMPNAME_OURSTASH||| PAD_COMPNAME_PV||| PAD_COMPNAME_TYPE||| PAD_RESTORE_LOCAL||| PAD_SAVE_LOCAL||| PAD_SAVE_SETNULLPAD||| PAD_SETSV||| PAD_SET_CUR_NOSAVE||| PAD_SET_CUR||| PAD_SVl||| PAD_SV||| PERLIO_FUNCS_CAST|5.009003||p PERLIO_FUNCS_DECL|5.009003||p PERL_ABS|5.008001||p PERL_ARGS_ASSERT_CROAK_XS_USAGE|||p PERL_BCDVERSION|5.024000||p PERL_GCC_BRACE_GROUPS_FORBIDDEN|5.008001||p PERL_HASH|5.003070||p PERL_INT_MAX|5.003070||p PERL_INT_MIN|5.003070||p PERL_LONG_MAX|5.003070||p PERL_LONG_MIN|5.003070||p PERL_MAGIC_arylen|5.007002||p PERL_MAGIC_backref|5.007002||p PERL_MAGIC_bm|5.007002||p PERL_MAGIC_collxfrm|5.007002||p PERL_MAGIC_dbfile|5.007002||p PERL_MAGIC_dbline|5.007002||p PERL_MAGIC_defelem|5.007002||p PERL_MAGIC_envelem|5.007002||p PERL_MAGIC_env|5.007002||p PERL_MAGIC_ext|5.007002||p PERL_MAGIC_fm|5.007002||p PERL_MAGIC_glob|5.024000||p PERL_MAGIC_isaelem|5.007002||p PERL_MAGIC_isa|5.007002||p PERL_MAGIC_mutex|5.024000||p PERL_MAGIC_nkeys|5.007002||p PERL_MAGIC_overload_elem|5.024000||p PERL_MAGIC_overload_table|5.007002||p PERL_MAGIC_overload|5.024000||p PERL_MAGIC_pos|5.007002||p PERL_MAGIC_qr|5.007002||p PERL_MAGIC_regdata|5.007002||p PERL_MAGIC_regdatum|5.007002||p PERL_MAGIC_regex_global|5.007002||p PERL_MAGIC_shared_scalar|5.007003||p PERL_MAGIC_shared|5.007003||p PERL_MAGIC_sigelem|5.007002||p PERL_MAGIC_sig|5.007002||p PERL_MAGIC_substr|5.007002||p PERL_MAGIC_sv|5.007002||p PERL_MAGIC_taint|5.007002||p PERL_MAGIC_tiedelem|5.007002||p PERL_MAGIC_tiedscalar|5.007002||p PERL_MAGIC_tied|5.007002||p PERL_MAGIC_utf8|5.008001||p PERL_MAGIC_uvar_elem|5.007003||p PERL_MAGIC_uvar|5.007002||p PERL_MAGIC_vec|5.007002||p PERL_MAGIC_vstring|5.008001||p PERL_PV_ESCAPE_ALL|5.009004||p PERL_PV_ESCAPE_FIRSTCHAR|5.009004||p PERL_PV_ESCAPE_NOBACKSLASH|5.009004||p PERL_PV_ESCAPE_NOCLEAR|5.009004||p PERL_PV_ESCAPE_QUOTE|5.009004||p PERL_PV_ESCAPE_RE|5.009005||p PERL_PV_ESCAPE_UNI_DETECT|5.009004||p PERL_PV_ESCAPE_UNI|5.009004||p PERL_PV_PRETTY_DUMP|5.009004||p PERL_PV_PRETTY_ELLIPSES|5.010000||p PERL_PV_PRETTY_LTGT|5.009004||p PERL_PV_PRETTY_NOCLEAR|5.010000||p PERL_PV_PRETTY_QUOTE|5.009004||p PERL_PV_PRETTY_REGPROP|5.009004||p PERL_QUAD_MAX|5.003070||p PERL_QUAD_MIN|5.003070||p PERL_REVISION|5.006000||p PERL_SCAN_ALLOW_UNDERSCORES|5.007003||p PERL_SCAN_DISALLOW_PREFIX|5.007003||p PERL_SCAN_GREATER_THAN_UV_MAX|5.007003||p PERL_SCAN_SILENT_ILLDIGIT|5.008001||p PERL_SHORT_MAX|5.003070||p PERL_SHORT_MIN|5.003070||p PERL_SIGNALS_UNSAFE_FLAG|5.008001||p PERL_SUBVERSION|5.006000||p PERL_SYS_INIT3||5.006000| PERL_SYS_INIT||| PERL_SYS_TERM||5.024000| PERL_UCHAR_MAX|5.003070||p PERL_UCHAR_MIN|5.003070||p PERL_UINT_MAX|5.003070||p PERL_UINT_MIN|5.003070||p PERL_ULONG_MAX|5.003070||p PERL_ULONG_MIN|5.003070||p PERL_UNUSED_ARG|5.009003||p PERL_UNUSED_CONTEXT|5.009004||p PERL_UNUSED_DECL|5.007002||p PERL_UNUSED_RESULT|5.021001||p PERL_UNUSED_VAR|5.007002||p PERL_UQUAD_MAX|5.003070||p PERL_UQUAD_MIN|5.003070||p PERL_USE_GCC_BRACE_GROUPS|5.009004||p PERL_USHORT_MAX|5.003070||p PERL_USHORT_MIN|5.003070||p PERL_VERSION|5.006000||p PL_DBsignal|5.005000||p PL_DBsingle|||pn PL_DBsub|||pn PL_DBtrace|||pn PL_Sv|5.005000||p PL_bufend|5.024000||p PL_bufptr|5.024000||p PL_check||5.006000| PL_compiling|5.004050||p PL_comppad_name||5.017004| PL_comppad||5.008001| PL_copline|5.024000||p PL_curcop|5.004050||p PL_curpad||5.005000| PL_curstash|5.004050||p PL_debstash|5.004050||p PL_defgv|5.004050||p PL_diehook|5.004050||p PL_dirty|5.004050||p PL_dowarn|||pn PL_errgv|5.004050||p PL_error_count|5.024000||p PL_expect|5.024000||p PL_hexdigit|5.005000||p PL_hints|5.005000||p PL_in_my_stash|5.024000||p PL_in_my|5.024000||p PL_keyword_plugin||5.011002| PL_last_in_gv|||n PL_laststatval|5.005000||p PL_lex_state|5.024000||p PL_lex_stuff|5.024000||p PL_linestr|5.024000||p PL_modglobal||5.005000|n PL_na|5.004050||pn PL_no_modify|5.006000||p PL_ofsgv|||n PL_opfreehook||5.011000|n PL_parser|5.009005||p PL_peepp||5.007003|n PL_perl_destruct_level|5.004050||p PL_perldb|5.004050||p PL_ppaddr|5.006000||p PL_rpeepp||5.013005|n PL_rsfp_filters|5.024000||p PL_rsfp|5.024000||p PL_rs|||n PL_signals|5.008001||p PL_stack_base|5.004050||p PL_stack_sp|5.004050||p PL_statcache|5.005000||p PL_stdingv|5.004050||p PL_sv_arenaroot|5.004050||p PL_sv_no|5.004050||pn PL_sv_undef|5.004050||pn PL_sv_yes|5.004050||pn PL_tainted|5.004050||p PL_tainting|5.004050||p PL_tokenbuf|5.024000||p POP_MULTICALL||5.024000| POPi|||n POPl|||n POPn|||n POPpbytex||5.007001|n POPpx||5.005030|n POPp|||n POPs|||n POPul||5.006000|n POPu||5.004000|n PTR2IV|5.006000||p PTR2NV|5.006000||p PTR2UV|5.006000||p PTR2nat|5.009003||p PTR2ul|5.007001||p PTRV|5.006000||p PUSHMARK||| PUSH_MULTICALL||5.024000| PUSHi||| PUSHmortal|5.009002||p PUSHn||| PUSHp||| PUSHs||| PUSHu|5.004000||p PUTBACK||| PadARRAY||5.024000| PadMAX||5.024000| PadlistARRAY||5.024000| PadlistMAX||5.024000| PadlistNAMESARRAY||5.024000| PadlistNAMESMAX||5.024000| PadlistNAMES||5.024000| PadlistREFCNT||5.017004| PadnameIsOUR||| PadnameIsSTATE||| PadnameLEN||5.024000| PadnameOURSTASH||| PadnameOUTER||| PadnamePV||5.024000| PadnameREFCNT_dec||5.024000| PadnameREFCNT||5.024000| PadnameSV||5.024000| PadnameTYPE||| PadnameUTF8||5.021007| PadnamelistARRAY||5.024000| PadnamelistMAX||5.024000| PadnamelistREFCNT_dec||5.024000| PadnamelistREFCNT||5.024000| PerlIO_clearerr||5.007003| PerlIO_close||5.007003| PerlIO_context_layers||5.009004| PerlIO_eof||5.007003| PerlIO_error||5.007003| PerlIO_fileno||5.007003| PerlIO_fill||5.007003| PerlIO_flush||5.007003| PerlIO_get_base||5.007003| PerlIO_get_bufsiz||5.007003| PerlIO_get_cnt||5.007003| PerlIO_get_ptr||5.007003| PerlIO_read||5.007003| PerlIO_restore_errno||| PerlIO_save_errno||| PerlIO_seek||5.007003| PerlIO_set_cnt||5.007003| PerlIO_set_ptrcnt||5.007003| PerlIO_setlinebuf||5.007003| PerlIO_stderr||5.007003| PerlIO_stdin||5.007003| PerlIO_stdout||5.007003| PerlIO_tell||5.007003| PerlIO_unread||5.007003| PerlIO_write||5.007003| PoisonFree|5.009004||p PoisonNew|5.009004||p PoisonWith|5.009004||p Poison|5.008000||p READ_XDIGIT||5.017006| RESTORE_LC_NUMERIC||5.024000| RETVAL|||n Renewc||| Renew||| SAVECLEARSV||| SAVECOMPPAD||| SAVEPADSV||| SAVETMPS||| SAVE_DEFSV|5.004050||p SPAGAIN||| SP||| START_EXTERN_C|5.005000||p START_MY_CXT|5.007003||p STMT_END|||p STMT_START|||p STORE_LC_NUMERIC_FORCE_TO_UNDERLYING||5.024000| STORE_LC_NUMERIC_SET_TO_NEEDED||5.024000| STR_WITH_LEN|5.009003||p ST||| SV_CONST_RETURN|5.009003||p SV_COW_DROP_PV|5.008001||p SV_COW_SHARED_HASH_KEYS|5.009005||p SV_GMAGIC|5.007002||p SV_HAS_TRAILING_NUL|5.009004||p SV_IMMEDIATE_UNREF|5.007001||p SV_MUTABLE_RETURN|5.009003||p SV_NOSTEAL|5.009002||p SV_SMAGIC|5.009003||p SV_UTF8_NO_ENCODING|5.008001||p SVfARG|5.009005||p SVf_UTF8|5.006000||p SVf|5.006000||p SVt_INVLIST||5.019002| SVt_IV||| SVt_NULL||| SVt_NV||| SVt_PVAV||| SVt_PVCV||| SVt_PVFM||| SVt_PVGV||| SVt_PVHV||| SVt_PVIO||| SVt_PVIV||| SVt_PVLV||| SVt_PVMG||| SVt_PVNV||| SVt_PV||| SVt_REGEXP||5.011000| Safefree||| Slab_Alloc||| Slab_Free||| Slab_to_ro||| Slab_to_rw||| StructCopy||| SvCUR_set||| SvCUR||| SvEND||| SvGAMAGIC||5.006001| SvGETMAGIC|5.004050||p SvGROW||| SvIOK_UV||5.006000| SvIOK_notUV||5.006000| SvIOK_off||| SvIOK_only_UV||5.006000| SvIOK_only||| SvIOK_on||| SvIOKp||| SvIOK||| SvIVX||| SvIV_nomg|5.009001||p SvIV_set||| SvIVx||| SvIV||| SvIsCOW_shared_hash||5.008003| SvIsCOW||5.008003| SvLEN_set||| SvLEN||| SvLOCK||5.007003| SvMAGIC_set|5.009003||p SvNIOK_off||| SvNIOKp||| SvNIOK||| SvNOK_off||| SvNOK_only||| SvNOK_on||| SvNOKp||| SvNOK||| SvNVX||| SvNV_nomg||5.013002| SvNV_set||| SvNVx||| SvNV||| SvOK||| SvOOK_offset||5.011000| SvOOK||| SvPOK_off||| SvPOK_only_UTF8||5.006000| SvPOK_only||| SvPOK_on||| SvPOKp||| SvPOK||| SvPVX_const|5.009003||p SvPVX_mutable|5.009003||p SvPVX||| SvPV_const|5.009003||p SvPV_flags_const_nolen|5.009003||p SvPV_flags_const|5.009003||p SvPV_flags_mutable|5.009003||p SvPV_flags|5.007002||p SvPV_force_flags_mutable|5.009003||p SvPV_force_flags_nolen|5.009003||p SvPV_force_flags|5.007002||p SvPV_force_mutable|5.009003||p SvPV_force_nolen|5.009003||p SvPV_force_nomg_nolen|5.009003||p SvPV_force_nomg|5.007002||p SvPV_force|||p SvPV_mutable|5.009003||p SvPV_nolen_const|5.009003||p SvPV_nolen|5.006000||p SvPV_nomg_const_nolen|5.009003||p SvPV_nomg_const|5.009003||p SvPV_nomg_nolen|5.013007||p SvPV_nomg|5.007002||p SvPV_renew|5.009003||p SvPV_set||| SvPVbyte_force||5.009002| SvPVbyte_nolen||5.006000| SvPVbytex_force||5.006000| SvPVbytex||5.006000| SvPVbyte|5.006000||p SvPVutf8_force||5.006000| SvPVutf8_nolen||5.006000| SvPVutf8x_force||5.006000| SvPVutf8x||5.006000| SvPVutf8||5.006000| SvPVx||| SvPV||| SvREFCNT_dec_NN||5.017007| SvREFCNT_dec||| SvREFCNT_inc_NN|5.009004||p SvREFCNT_inc_simple_NN|5.009004||p SvREFCNT_inc_simple_void_NN|5.009004||p SvREFCNT_inc_simple_void|5.009004||p SvREFCNT_inc_simple|5.009004||p SvREFCNT_inc_void_NN|5.009004||p SvREFCNT_inc_void|5.009004||p SvREFCNT_inc|||p SvREFCNT||| SvROK_off||| SvROK_on||| SvROK||| SvRV_set|5.009003||p SvRV||| SvRXOK|5.009005||p SvRX|5.009005||p SvSETMAGIC||| SvSHARED_HASH|5.009003||p SvSHARE||5.007003| SvSTASH_set|5.009003||p SvSTASH||| SvSetMagicSV_nosteal||5.004000| SvSetMagicSV||5.004000| SvSetSV_nosteal||5.004000| SvSetSV||| SvTAINTED_off||5.004000| SvTAINTED_on||5.004000| SvTAINTED||5.004000| SvTAINT||| SvTHINKFIRST||| SvTRUE_nomg||5.013006| SvTRUE||| SvTYPE||| SvUNLOCK||5.007003| SvUOK|5.007001|5.006000|p SvUPGRADE||| SvUTF8_off||5.006000| SvUTF8_on||5.006000| SvUTF8||5.006000| SvUVXx|5.004000||p SvUVX|5.004000||p SvUV_nomg|5.009001||p SvUV_set|5.009003||p SvUVx|5.004000||p SvUV|5.004000||p SvVOK||5.008001| SvVSTRING_mg|5.009004||p THIS|||n UNDERBAR|5.009002||p UTF8SKIP||5.006000| UTF8_MAXBYTES|5.009002||p UVCHR_SKIP||5.022000| UVSIZE|5.006000||p UVTYPE|5.006000||p UVXf|5.007001||p UVof|5.006000||p UVuf|5.006000||p UVxf|5.006000||p WARN_ALL|5.006000||p WARN_AMBIGUOUS|5.006000||p WARN_ASSERTIONS|5.024000||p WARN_BAREWORD|5.006000||p WARN_CLOSED|5.006000||p WARN_CLOSURE|5.006000||p WARN_DEBUGGING|5.006000||p WARN_DEPRECATED|5.006000||p WARN_DIGIT|5.006000||p WARN_EXEC|5.006000||p WARN_EXITING|5.006000||p WARN_GLOB|5.006000||p WARN_INPLACE|5.006000||p WARN_INTERNAL|5.006000||p WARN_IO|5.006000||p WARN_LAYER|5.008000||p WARN_MALLOC|5.006000||p WARN_MISC|5.006000||p WARN_NEWLINE|5.006000||p WARN_NUMERIC|5.006000||p WARN_ONCE|5.006000||p WARN_OVERFLOW|5.006000||p WARN_PACK|5.006000||p WARN_PARENTHESIS|5.006000||p WARN_PIPE|5.006000||p WARN_PORTABLE|5.006000||p WARN_PRECEDENCE|5.006000||p WARN_PRINTF|5.006000||p WARN_PROTOTYPE|5.006000||p WARN_QW|5.006000||p WARN_RECURSION|5.006000||p WARN_REDEFINE|5.006000||p WARN_REGEXP|5.006000||p WARN_RESERVED|5.006000||p WARN_SEMICOLON|5.006000||p WARN_SEVERE|5.006000||p WARN_SIGNAL|5.006000||p WARN_SUBSTR|5.006000||p WARN_SYNTAX|5.006000||p WARN_TAINT|5.006000||p WARN_THREADS|5.008000||p WARN_UNINITIALIZED|5.006000||p WARN_UNOPENED|5.006000||p WARN_UNPACK|5.006000||p WARN_UNTIE|5.006000||p WARN_UTF8|5.006000||p WARN_VOID|5.006000||p WIDEST_UTYPE|5.015004||p XCPT_CATCH|5.009002||p XCPT_RETHROW|5.009002||p XCPT_TRY_END|5.009002||p XCPT_TRY_START|5.009002||p XPUSHi||| XPUSHmortal|5.009002||p XPUSHn||| XPUSHp||| XPUSHs||| XPUSHu|5.004000||p XSPROTO|5.010000||p XSRETURN_EMPTY||| XSRETURN_IV||| XSRETURN_NO||| XSRETURN_NV||| XSRETURN_PV||| XSRETURN_UNDEF||| XSRETURN_UV|5.008001||p XSRETURN_YES||| XSRETURN|||p XST_mIV||| XST_mNO||| XST_mNV||| XST_mPV||| XST_mUNDEF||| XST_mUV|5.008001||p XST_mYES||| XS_APIVERSION_BOOTCHECK||5.024000| XS_EXTERNAL||5.024000| XS_INTERNAL||5.024000| XS_VERSION_BOOTCHECK||5.024000| XS_VERSION||| XSprePUSH|5.006000||p XS||| XopDISABLE||5.024000| XopENABLE||5.024000| XopENTRYCUSTOM||5.024000| XopENTRY_set||5.024000| XopENTRY||5.024000| XopFLAGS||5.013007| ZeroD|5.009002||p Zero||| _aMY_CXT|5.007003||p _core_swash_init||| _load_PL_utf8_foldclosures||| _pMY_CXT|5.007003||p _to_fold_latin1||| _to_upper_title_latin1||| _to_utf8_case||| aMY_CXT_|5.007003||p aMY_CXT|5.007003||p aTHXR_|5.024000||p aTHXR|5.024000||p aTHX_|5.006000||p aTHX|5.006000||p add_above_Latin1_folds||| add_data|||n add_multi_match||| add_utf16_textfilter||| adjust_size_and_find_bucket|||n advance_one_LB||| advance_one_SB||| advance_one_WB||| alloc_maybe_populate_EXACT||| allocmy||| amagic_call||| amagic_cmp_locale||| amagic_cmp||| amagic_deref_call||5.013007| amagic_i_ncmp||| amagic_is_enabled||| amagic_ncmp||| anonymise_cv_maybe||| any_dup||| ao||| apply_attrs_my||| apply_attrs||| apply||| assert_uft8_cache_coherent||| assignment_type||| atfork_lock||5.007003|n atfork_unlock||5.007003|n av_arylen_p||5.009003| av_clear||| av_delete||5.006000| av_exists||5.006000| av_extend_guts||| av_extend||| av_fetch||| av_fill||| av_iter_p||5.011000| av_len||| av_make||| av_pop||| av_push||| av_reify||| av_shift||| av_store||| av_tindex||5.017009| av_top_index||5.017009| av_undef||| av_unshift||| ax|||n backup_one_LB||| backup_one_SB||| backup_one_WB||| bad_type_gv||| bad_type_pv||| bind_match||| block_end||5.004000| block_gimme||5.004000| block_start||5.004000| blockhook_register||5.013003| boolSV|5.004000||p boot_core_PerlIO||| boot_core_UNIVERSAL||| boot_core_mro||| bytes_cmp_utf8||5.013007| cBOOL|5.013000||p call_argv|5.006000||p call_atexit||5.006000| call_list||5.004000| call_method|5.006000||p call_pv|5.006000||p call_sv|5.006000||p caller_cx|5.013005|5.006000|p calloc||5.007002|n cando||| cast_i32||5.006000|n cast_iv||5.006000|n cast_ulong||5.006000|n cast_uv||5.006000|n check_type_and_open||| check_uni||| checkcomma||| ckWARN|5.006000||p ck_entersub_args_core||| ck_entersub_args_list||5.013006| ck_entersub_args_proto_or_list||5.013006| ck_entersub_args_proto||5.013006| ck_warner_d||5.011001|v ck_warner||5.011001|v ckwarn_common||| ckwarn_d||5.009003| ckwarn||5.009003| clear_defarray||5.023008| clear_special_blocks||| clone_params_del|||n clone_params_new|||n closest_cop||| cntrl_to_mnemonic|||n compute_EXACTish|||n construct_ahocorasick_from_trie||| cop_free||| cop_hints_2hv||5.013007| cop_hints_fetch_pvn||5.013007| cop_hints_fetch_pvs||5.013007| cop_hints_fetch_pv||5.013007| cop_hints_fetch_sv||5.013007| cophh_2hv||5.013007| cophh_copy||5.013007| cophh_delete_pvn||5.013007| cophh_delete_pvs||5.013007| cophh_delete_pv||5.013007| cophh_delete_sv||5.013007| cophh_fetch_pvn||5.013007| cophh_fetch_pvs||5.013007| cophh_fetch_pv||5.013007| cophh_fetch_sv||5.013007| cophh_free||5.013007| cophh_new_empty||5.024000| cophh_store_pvn||5.013007| cophh_store_pvs||5.013007| cophh_store_pv||5.013007| cophh_store_sv||5.013007| core_prototype||| coresub_op||| cr_textfilter||| croak_memory_wrap|5.019003||pn croak_no_mem|||n croak_no_modify|5.013003||pn croak_nocontext|||pvn croak_popstack|||n croak_sv|5.013001||p croak_xs_usage|5.010001||pn croak|||v csighandler||5.009003|n current_re_engine||| curse||| custom_op_desc||5.007003| custom_op_get_field||| custom_op_name||5.007003| custom_op_register||5.013007| custom_op_xop||5.013007| cv_clone_into||| cv_clone||| cv_const_sv_or_av|||n cv_const_sv||5.003070|n cv_dump||| cv_forget_slab||| cv_get_call_checker||5.013006| cv_name||5.021005| cv_set_call_checker_flags||5.021004| cv_set_call_checker||5.013006| cv_undef_flags||| cv_undef||| cvgv_from_hek||| cvgv_set||| cvstash_set||| cx_dump||5.005000| cx_dup||| cxinc||| dAXMARK|5.009003||p dAX|5.007002||p dITEMS|5.007002||p dMARK||| dMULTICALL||5.009003| dMY_CXT_SV|5.007003||p dMY_CXT|5.007003||p dNOOP|5.006000||p dORIGMARK||| dSP||| dTHR|5.004050||p dTHXR|5.024000||p dTHXa|5.006000||p dTHXoa|5.006000||p dTHX|5.006000||p dUNDERBAR|5.009002||p dVAR|5.009003||p dXCPT|5.009002||p dXSARGS||| dXSI32||| dXSTARG|5.006000||p deb_curcv||| deb_nocontext|||vn deb_stack_all||| deb_stack_n||| debop||5.005000| debprofdump||5.005000| debprof||| debstackptrs||5.007003| debstack||5.007003| debug_start_match||| deb||5.007003|v defelem_target||| del_sv||| delimcpy||5.004000|n deprecate_commaless_var_list||| despatch_signals||5.007001| destroy_matcher||| die_nocontext|||vn die_sv|5.013001||p die_unwind||| die|||v dirp_dup||| div128||| djSP||| do_aexec5||| do_aexec||| do_aspawn||| do_binmode||5.004050| do_chomp||| do_close||| do_delete_local||| do_dump_pad||| do_eof||| do_exec3||| do_execfree||| do_exec||| do_gv_dump||5.006000| do_gvgv_dump||5.006000| do_hv_dump||5.006000| do_ipcctl||| do_ipcget||| do_join||| do_magic_dump||5.006000| do_msgrcv||| do_msgsnd||| do_ncmp||| do_oddball||| do_op_dump||5.006000| do_open9||5.006000| do_openn||5.007001| do_open||5.003070| do_pmop_dump||5.006000| do_print||| do_readline||| do_seek||| do_semop||| do_shmio||| do_smartmatch||| do_spawn_nowait||| do_spawn||| do_sprintf||| do_sv_dump||5.006000| do_sysseek||| do_tell||| do_trans_complex_utf8||| do_trans_complex||| do_trans_count_utf8||| do_trans_count||| do_trans_simple_utf8||| do_trans_simple||| do_trans||| do_vecget||| do_vecset||| do_vop||| docatch||| doeval_compile||| dofile||| dofindlabel||| doform||| doing_taint||5.008001|n dooneliner||| doopen_pm||| doparseform||| dopoptoeval||| dopoptogivenfor||| dopoptolabel||| dopoptoloop||| dopoptosub_at||| dopoptowhen||| doref||5.009003| dounwind||| dowantarray||| drand48_init_r|||n drand48_r|||n dtrace_probe_call||| dtrace_probe_load||| dtrace_probe_op||| dtrace_probe_phase||| dump_all_perl||| dump_all||5.006000| dump_c_backtrace||| dump_eval||5.006000| dump_exec_pos||| dump_form||5.006000| dump_indent||5.006000|v dump_mstats||| dump_packsubs_perl||| dump_packsubs||5.006000| dump_sub_perl||| dump_sub||5.006000| dump_sv_child||| dump_trie_interim_list||| dump_trie_interim_table||| dump_trie||| dump_vindent||5.006000| dumpuntil||| dup_attrlist||| edit_distance|||n eval_pv|5.006000||p eval_sv|5.006000||p exec_failed||| expect_number||| fbm_compile||5.005000| fbm_instr||5.005000| feature_is_enabled||| filter_add||| filter_del||| filter_gets||| filter_read||| finalize_optree||| finalize_op||| find_and_forget_pmops||| find_array_subscript||| find_beginning||| find_byclass||| find_default_stash||| find_hash_subscript||| find_in_my_stash||| find_lexical_cv||| find_runcv_where||| find_runcv||5.008001| find_rundefsv||5.013002| find_script||| first_symbol|||n fixup_errno_string||| foldEQ_latin1||5.013008|n foldEQ_locale||5.013002|n foldEQ_utf8||5.013002| foldEQ||5.013002|n fold_constants||| forbid_setid||| force_ident_maybe_lex||| force_ident||| force_list||| force_next||| force_strict_version||| force_version||| force_word||| forget_pmop||| form_nocontext|||vn form||5.004000|v fp_dup||| fprintf_nocontext|||vn free_c_backtrace||| free_global_struct||| free_tied_hv_pool||| free_tmps||| gen_constant_list||| get_ANYOF_cp_list_for_ssc||| get_and_check_backslash_N_name||| get_aux_mg||| get_av|5.006000||p get_c_backtrace_dump||| get_c_backtrace||| get_context||5.006000|n get_cvn_flags||| get_cvs|5.011000||p get_cv|5.006000||p get_db_sub||| get_debug_opts||| get_hash_seed||| get_hv|5.006000||p get_mstats||| get_no_modify||| get_num||| get_op_descs||5.005000| get_op_names||5.005000| get_opargs||| get_ppaddr||5.006000| get_sv|5.006000||p get_vtbl||5.005030| getcwd_sv||5.007002| getenv_len||| glob_2number||| glob_assign_glob||| gp_dup||| gp_free||| gp_ref||| grok_atoUV|||n grok_bin|5.007003||p grok_bslash_N||| grok_hex|5.007003||p grok_infnan||5.021004| grok_number_flags||5.021002| grok_number|5.007002||p grok_numeric_radix|5.007002||p grok_oct|5.007003||p group_end||| gv_AVadd||| gv_HVadd||| gv_IOadd||| gv_SVadd||| gv_add_by_type||5.011000| gv_autoload4||5.004000| gv_autoload_pvn||5.015004| gv_autoload_pv||5.015004| gv_autoload_sv||5.015004| gv_check||| gv_const_sv||5.009003| gv_dump||5.006000| gv_efullname3||5.003070| gv_efullname4||5.006001| gv_efullname||| gv_fetchfile_flags||5.009005| gv_fetchfile||| gv_fetchmeth_autoload||5.007003| gv_fetchmeth_internal||| gv_fetchmeth_pv_autoload||5.015004| gv_fetchmeth_pvn_autoload||5.015004| gv_fetchmeth_pvn||5.015004| gv_fetchmeth_pv||5.015004| gv_fetchmeth_sv_autoload||5.015004| gv_fetchmeth_sv||5.015004| gv_fetchmethod_autoload||5.004000| gv_fetchmethod||| gv_fetchmeth||| gv_fetchpvn_flags|5.009002||p gv_fetchpvs|5.009004||p gv_fetchpv||| gv_fetchsv||| gv_fullname3||5.003070| gv_fullname4||5.006001| gv_fullname||| gv_handler||5.007001| gv_init_pvn||| gv_init_pv||5.015004| gv_init_svtype||| gv_init_sv||5.015004| gv_init||| gv_is_in_main||| gv_magicalize_isa||| gv_magicalize||| gv_name_set||5.009004| gv_override||| gv_setref||| gv_stashpvn_internal||| gv_stashpvn|5.003070||p gv_stashpvs|5.009003||p gv_stashpv||| gv_stashsvpvn_cached||| gv_stashsv||| handle_named_backref||| handle_possible_posix||| handle_regex_sets||| he_dup||| hek_dup||| hfree_next_entry||| hsplit||| hv_assert||| hv_auxinit_internal|||n hv_auxinit||| hv_clear_placeholders||5.009001| hv_clear||| hv_common_key_len||5.010000| hv_common||5.010000| hv_copy_hints_hv||5.009004| hv_delayfree_ent||5.004000| hv_delete_ent||5.003070| hv_delete||| hv_eiter_p||5.009003| hv_eiter_set||5.009003| hv_ename_add||| hv_ename_delete||| hv_exists_ent||5.003070| hv_exists||| hv_fetch_ent||5.003070| hv_fetchs|5.009003||p hv_fetch||| hv_fill||5.013002| hv_free_ent_ret||| hv_free_entries||| hv_free_ent||5.004000| hv_iterinit||| hv_iterkeysv||5.003070| hv_iterkey||| hv_iternextsv||| hv_iternext||| hv_iterval||| hv_ksplit||5.003070| hv_magic_check|||n hv_magic||| hv_name_set||5.009003| hv_notallowed||| hv_placeholders_get||5.009003| hv_placeholders_p||| hv_placeholders_set||5.009003| hv_rand_set||5.018000| hv_riter_p||5.009003| hv_riter_set||5.009003| hv_scalar||5.009001| hv_store_ent||5.003070| hv_stores|5.009004||p hv_store||| hv_undef_flags||| hv_undef||| ibcmp_locale||5.004000| ibcmp_utf8||5.007003| ibcmp||| incline||| incpush_if_exists||| incpush_use_sep||| incpush||| ingroup||| init_argv_symbols||| init_constants||| init_dbargs||| init_debugger||| init_global_struct||| init_ids||| init_interp||| init_main_stash||| init_perllib||| init_postdump_symbols||| init_predump_symbols||| init_stacks||5.005000| init_tm||5.007002| inplace_aassign||| instr|||n intro_my||5.004000| intuit_method||| intuit_more||| invert||| invoke_exception_hook||| io_close||| isALNUMC|5.006000||p isALPHANUMERIC||5.017008| isALPHA||| isASCII|5.006000||p isBLANK|5.006001||p isCNTRL|5.006000||p isDIGIT||| isFOO_lc||| isFOO_utf8_lc||| isGCB|||n isGRAPH|5.006000||p isIDCONT||5.017008| isIDFIRST||| isLB||| isLOWER||| isOCTAL||5.013005| isPRINT|5.004000||p isPSXSPC|5.006001||p isPUNCT|5.006000||p isSB||| isSPACE||| isUPPER||| isUTF8_CHAR||5.021001| isWB||| isWORDCHAR||5.013006| isXDIGIT|5.006000||p is_an_int||| is_ascii_string||5.011000| is_handle_constructor|||n is_invariant_string||5.021007|n is_lvalue_sub||5.007001| is_safe_syscall||5.019004| is_ssc_worth_it|||n is_utf8_char_buf||5.015008|n is_utf8_common||| is_utf8_string_loclen||5.009003|n is_utf8_string_loc||5.008001|n is_utf8_string||5.006001|n isa_lookup||| isinfnansv||| isinfnan||5.021004|n items|||n ix|||n jmaybe||| join_exact||| keyword_plugin_standard||| keyword||| leave_scope||| lex_stuff_pvs||5.013005| listkids||| list||| load_module_nocontext|||vn load_module|5.006000||pv localize||| looks_like_bool||| looks_like_number||| lop||| mPUSHi|5.009002||p mPUSHn|5.009002||p mPUSHp|5.009002||p mPUSHs|5.010001||p mPUSHu|5.009002||p mXPUSHi|5.009002||p mXPUSHn|5.009002||p mXPUSHp|5.009002||p mXPUSHs|5.010001||p mXPUSHu|5.009002||p magic_clear_all_env||| magic_cleararylen_p||| magic_clearenv||| magic_clearhints||| magic_clearhint||| magic_clearisa||| magic_clearpack||| magic_clearsig||| magic_copycallchecker||| magic_dump||5.006000| magic_existspack||| magic_freearylen_p||| magic_freeovrld||| magic_getarylen||| magic_getdebugvar||| magic_getdefelem||| magic_getnkeys||| magic_getpack||| magic_getpos||| magic_getsig||| magic_getsubstr||| magic_gettaint||| magic_getuvar||| magic_getvec||| magic_get||| magic_killbackrefs||| magic_methcall1||| magic_methcall|||v magic_methpack||| magic_nextpack||| magic_regdata_cnt||| magic_regdatum_get||| magic_regdatum_set||| magic_scalarpack||| magic_set_all_env||| magic_setarylen||| magic_setcollxfrm||| magic_setdbline||| magic_setdebugvar||| magic_setdefelem||| magic_setenv||| magic_sethint||| magic_setisa||| magic_setlvref||| magic_setmglob||| magic_setnkeys||| magic_setpack||| magic_setpos||| magic_setregexp||| magic_setsig||| magic_setsubstr||| magic_settaint||| magic_setutf8||| magic_setuvar||| magic_setvec||| magic_set||| magic_sizepack||| magic_wipepack||| make_matcher||| make_trie||| malloc_good_size|||n malloced_size|||n malloc||5.007002|n markstack_grow||5.021001| matcher_matches_sv||| maybe_multimagic_gv||| mayberelocate||| measure_struct||| memEQs|5.009005||p memEQ|5.004000||p memNEs|5.009005||p memNE|5.004000||p mem_collxfrm||| mem_log_alloc|||n mem_log_common|||n mem_log_free|||n mem_log_realloc|||n mess_alloc||| mess_nocontext|||pvn mess_sv|5.013001||p mess|5.006000||pv mfree||5.007002|n mg_clear||| mg_copy||| mg_dup||| mg_find_mglob||| mg_findext|5.013008||pn mg_find|||n mg_free_type||5.013006| mg_free||| mg_get||| mg_localize||| mg_magical|||n mg_set||| mg_size||5.005000| mini_mktime||5.007002|n minus_v||| missingterm||| mode_from_discipline||| modkids||| more_bodies||| more_sv||| moreswitches||| move_proto_attr||| mro_clean_isarev||| mro_gather_and_rename||| mro_get_from_name||5.010001| mro_get_linear_isa_dfs||| mro_get_linear_isa||5.009005| mro_get_private_data||5.010001| mro_isa_changed_in||| mro_meta_dup||| mro_meta_init||| mro_method_changed_in||5.009005| mro_package_moved||| mro_register||5.010001| mro_set_mro||5.010001| mro_set_private_data||5.010001| mul128||| mulexp10|||n multideref_stringify||| my_atof2||5.007002| my_atof||5.006000| my_attrs||| my_bcopy||5.004050|n my_bytes_to_utf8|||n my_bzero|||n my_chsize||| my_clearenv||| my_cxt_index||| my_cxt_init||| my_dirfd||5.009005|n my_exit_jump||| my_exit||| my_failure_exit||5.004000| my_fflush_all||5.006000| my_fork||5.007003|n my_kid||| my_lstat_flags||| my_lstat||5.024000| my_memcmp|||n my_memset|||n my_pclose||5.003070| my_popen_list||5.007001| my_popen||5.003070| my_setenv||| my_snprintf|5.009004||pvn my_socketpair||5.007003|n my_sprintf|5.009003||pvn my_stat_flags||| my_stat||5.024000| my_strftime||5.007002| my_strlcat|5.009004||pn my_strlcpy|5.009004||pn my_unexec||| my_vsnprintf||5.009004|n need_utf8|||n newANONATTRSUB||5.006000| newANONHASH||| newANONLIST||| newANONSUB||| newASSIGNOP||| newATTRSUB_x||| newATTRSUB||5.006000| newAVREF||| newAV||| newBINOP||| newCONDOP||| newCONSTSUB_flags||5.015006| newCONSTSUB|5.004050||p newCVREF||| newDEFSVOP||5.021006| newFORM||| newFOROP||5.013007| newGIVENOP||5.009003| newGIVWHENOP||| newGVOP||| newGVREF||| newGVgen_flags||5.015004| newGVgen||| newHVREF||| newHVhv||5.005000| newHV||| newIO||| newLISTOP||| newLOGOP||| newLOOPEX||| newLOOPOP||| newMETHOP_internal||| newMETHOP_named||5.021005| newMETHOP||5.021005| newMYSUB||5.017004| newNULLLIST||| newOP||| newPADOP||| newPMOP||| newPROG||| newPVOP||| newRANGE||| newRV_inc|5.004000||p newRV_noinc|5.004000||p newRV||| newSLICEOP||| newSTATEOP||| newSTUB||| newSUB||| newSVOP||| newSVREF||| newSV_type|5.009005||p newSVavdefelem||| newSVhek||5.009003| newSViv||| newSVnv||| newSVpadname||5.017004| newSVpv_share||5.013006| newSVpvf_nocontext|||vn newSVpvf||5.004000|v newSVpvn_flags|5.010001||p newSVpvn_share|5.007001||p newSVpvn_utf8|5.010001||p newSVpvn|5.004050||p newSVpvs_flags|5.010001||p newSVpvs_share|5.009003||p newSVpvs|5.009003||p newSVpv||| newSVrv||| newSVsv||| newSVuv|5.006000||p newSV||| newUNOP_AUX||5.021007| newUNOP||| newWHENOP||5.009003| newWHILEOP||5.013007| newXS_deffile||| newXS_len_flags||| newXSproto||5.006000| newXS||5.006000| new_constant||| new_he||| new_logop||| new_stackinfo||5.005000| new_version||5.009000| next_symbol||| nextargv||| nextchar||| ninstr|||n no_bareword_allowed||| no_fh_allowed||| no_op||| noperl_die|||vn not_a_number||| not_incrementable||| nothreadhook||5.008000| nuke_stacks||| num_overflow|||n oopsAV||| oopsHV||| op_append_elem||5.013006| op_append_list||5.013006| op_clear||| op_contextualize||5.013006| op_convert_list||5.021006| op_dump||5.006000| op_free||| op_integerize||| op_linklist||5.013006| op_lvalue_flags||| op_null||5.007002| op_parent|||n op_prepend_elem||5.013006| op_refcnt_lock||5.009002| op_refcnt_unlock||5.009002| op_relocate_sv||| op_sibling_splice||5.021002|n op_std_init||| open_script||| openn_cleanup||| openn_setup||| opmethod_stash||| opslab_force_free||| opslab_free_nopad||| opslab_free||| output_or_return_posix_warnings||| pMY_CXT_|5.007003||p pMY_CXT|5.007003||p pTHX_|5.006000||p pTHX|5.006000||p packWARN|5.007003||p pack_cat||5.007003| pack_rec||| package_version||| package||| packlist||5.008001| pad_add_anon||5.008001| pad_add_name_pvn||5.015001| pad_add_name_pvs||5.015001| pad_add_name_pv||5.015001| pad_add_name_sv||5.015001| pad_add_weakref||| pad_alloc_name||| pad_block_start||| pad_check_dup||| pad_compname_type||5.009003| pad_findlex||| pad_findmy_pvn||5.015001| pad_findmy_pvs||5.015001| pad_findmy_pv||5.015001| pad_findmy_sv||5.015001| pad_fixup_inner_anons||| pad_free||| pad_leavemy||| pad_new||5.008001| pad_push||| pad_reset||| pad_setsv||| pad_sv||| pad_swipe||| padlist_dup||| padlist_store||| padname_dup||| padname_free||| padnamelist_dup||| padnamelist_free||| parse_body||| parse_gv_stash_name||| parse_ident||| parse_lparen_question_flags||| parse_subsignature||| parse_unicode_opts||| parser_dup||| parser_free_nexttoke_ops||| parser_free||| path_is_searchable|||n peep||| pending_ident||| perl_alloc_using|||n perl_alloc|||n perl_clone_using|||n perl_clone|||n perl_construct|||n perl_destruct||5.007003|n perl_free|||n perl_parse||5.006000|n perl_run|||n pidgone||| pm_description||| pmop_dump||5.006000| pmruntime||| pmtrans||| pop_scope||| populate_ANYOF_from_invlist||| populate_isa|||v pregcomp||5.009005| pregexec||| pregfree2||5.011000| pregfree||| prescan_version||5.011004| printbuf||| printf_nocontext|||vn process_special_blocks||| ptr_hash|||n ptr_table_fetch||5.009005| ptr_table_find|||n ptr_table_free||5.009005| ptr_table_new||5.009005| ptr_table_split||5.009005| ptr_table_store||5.009005| push_scope||| put_charclass_bitmap_innards_common||| put_charclass_bitmap_innards_invlist||| put_charclass_bitmap_innards||| put_code_point||| put_range||| pv_display|5.006000||p pv_escape|5.009004||p pv_pretty|5.009004||p pv_uni_display||5.007003| qerror||| qsortsvu||| quadmath_format_needed|||n quadmath_format_single|||n re_compile||5.009005| re_croak2||| re_dup_guts||| re_exec_indentf|||v re_indentf|||v re_intuit_start||5.019001| re_intuit_string||5.006000| re_op_compile||| re_printf|||v realloc||5.007002|n reentrant_free||5.024000| reentrant_init||5.024000| reentrant_retry||5.024000|vn reentrant_size||5.024000| ref_array_or_hash||| refcounted_he_chain_2hv||| refcounted_he_fetch_pvn||| refcounted_he_fetch_pvs||| refcounted_he_fetch_pv||| refcounted_he_fetch_sv||| refcounted_he_free||| refcounted_he_inc||| refcounted_he_new_pvn||| refcounted_he_new_pvs||| refcounted_he_new_pv||| refcounted_he_new_sv||| refcounted_he_value||| refkids||| refto||| ref||5.024000| reg2Lanode||| reg_check_named_buff_matched|||n reg_named_buff_all||5.009005| reg_named_buff_exists||5.009005| reg_named_buff_fetch||5.009005| reg_named_buff_firstkey||5.009005| reg_named_buff_iter||| reg_named_buff_nextkey||5.009005| reg_named_buff_scalar||5.009005| reg_named_buff||| reg_node||| reg_numbered_buff_fetch||| reg_numbered_buff_length||| reg_numbered_buff_store||| reg_qr_package||| reg_recode||| reg_scan_name||| reg_skipcomment|||n reg_temp_copy||| reganode||| regatom||| regbranch||| regclass||| regcppop||| regcppush||| regcurly|||n regdump_extflags||| regdump_intflags||| regdump||5.005000| regdupe_internal||| regex_set_precedence|||n regexec_flags||5.005000| regfree_internal||5.009005| reghop3|||n reghop4|||n reghopmaybe3|||n reginclass||| reginitcolors||5.006000| reginsert||| regmatch||| regnext||5.005000| regnode_guts||| regpiece||| regprop||| regrepeat||| regtail_study||| regtail||| regtry||| reg||| repeatcpy|||n report_evil_fh||| report_redefined_cv||| report_uninit||| report_wrongway_fh||| require_pv||5.006000| require_tie_mod||| restore_magic||| rninstr|||n rpeep||| rsignal_restore||| rsignal_save||| rsignal_state||5.004000| rsignal||5.004000| run_body||| run_user_filter||| runops_debug||5.005000| runops_standard||5.005000| rv2cv_op_cv||5.013006| rvpv_dup||| rxres_free||| rxres_restore||| rxres_save||| safesyscalloc||5.006000|n safesysfree||5.006000|n safesysmalloc||5.006000|n safesysrealloc||5.006000|n same_dirent||| save_I16||5.004000| save_I32||| save_I8||5.006000| save_adelete||5.011000| save_aelem_flags||5.011000| save_aelem||5.004050| save_alloc||5.006000| save_aptr||| save_ary||| save_bool||5.008001| save_clearsv||| save_delete||| save_destructor_x||5.006000| save_destructor||5.006000| save_freeop||| save_freepv||| save_freesv||| save_generic_pvref||5.006001| save_generic_svref||5.005030| save_gp||5.004000| save_hash||| save_hdelete||5.011000| save_hek_flags|||n save_helem_flags||5.011000| save_helem||5.004050| save_hints||5.010001| save_hptr||| save_int||| save_item||| save_iv||5.005000| save_lines||| save_list||| save_long||| save_magic_flags||| save_mortalizesv||5.007001| save_nogv||| save_op||5.005000| save_padsv_and_mortalize||5.010001| save_pptr||| save_pushi32ptr||5.010001| save_pushptri32ptr||| save_pushptrptr||5.010001| save_pushptr||5.010001| save_re_context||5.006000| save_scalar_at||| save_scalar||| save_set_svflags||5.009000| save_shared_pvref||5.007003| save_sptr||| save_strlen||| save_svref||| save_vptr||5.006000| savepvn||| savepvs||5.009003| savepv||| savesharedpvn||5.009005| savesharedpvs||5.013006| savesharedpv||5.007003| savesharedsvpv||5.013006| savestack_grow_cnt||5.008001| savestack_grow||| savesvpv||5.009002| sawparens||| scalar_mod_type|||n scalarboolean||| scalarkids||| scalarseq||| scalarvoid||| scalar||| scan_bin||5.006000| scan_commit||| scan_const||| scan_formline||| scan_heredoc||| scan_hex||| scan_ident||| scan_inputsymbol||| scan_num||5.007001| scan_oct||| scan_pat||| scan_str||| scan_subst||| scan_trans||| scan_version||5.009001| scan_vstring||5.009005| scan_word||| search_const||| seed||5.008001| sequence_num||| set_ANYOF_arg||| set_caret_X||| set_context||5.006000|n set_numeric_local||5.006000| set_numeric_radix||5.006000| set_numeric_standard||5.006000| set_padlist|||n setdefout||| share_hek_flags||| share_hek||5.004000| should_warn_nl|||n si_dup||| sighandler|||n simplify_sort||| skip_to_be_ignored_text||| skipspace_flags||| softref2xv||| sortcv_stacked||| sortcv_xsub||| sortcv||| sortsv_flags||5.009003| sortsv||5.007003| space_join_names_mortal||| ss_dup||| ssc_add_range||| ssc_and||| ssc_anything||| ssc_clear_locale|||n ssc_cp_and||| ssc_finalize||| ssc_init||| ssc_intersection||| ssc_is_anything|||n ssc_is_cp_posixl_init|||n ssc_or||| ssc_union||| stack_grow||| start_subparse||5.004000| stdize_locale||| strEQ||| strGE||| strGT||| strLE||| strLT||| strNE||| str_to_version||5.006000| strip_return||| strnEQ||| strnNE||| study_chunk||| sub_crush_depth||| sublex_done||| sublex_push||| sublex_start||| sv_2bool_flags||5.013006| sv_2bool||| sv_2cv||| sv_2io||| sv_2iuv_common||| sv_2iuv_non_preserve||| sv_2iv_flags||5.009001| sv_2iv||| sv_2mortal||| sv_2nv_flags||5.013001| sv_2pv_flags|5.007002||p sv_2pv_nolen|5.006000||p sv_2pvbyte_nolen|5.006000||p sv_2pvbyte|5.006000||p sv_2pvutf8_nolen||5.006000| sv_2pvutf8||5.006000| sv_2pv||| sv_2uv_flags||5.009001| sv_2uv|5.004000||p sv_add_arena||| sv_add_backref||| sv_backoff|||n sv_bless||| sv_buf_to_ro||| sv_buf_to_rw||| sv_cat_decode||5.008001| sv_catpv_flags||5.013006| sv_catpv_mg|5.004050||p sv_catpv_nomg||5.013006| sv_catpvf_mg_nocontext|||pvn sv_catpvf_mg|5.006000|5.004000|pv sv_catpvf_nocontext|||vn sv_catpvf||5.004000|v sv_catpvn_flags||5.007002| sv_catpvn_mg|5.004050||p sv_catpvn_nomg|5.007002||p sv_catpvn||| sv_catpvs_flags||5.013006| sv_catpvs_mg||5.013006| sv_catpvs_nomg||5.013006| sv_catpvs|5.009003||p sv_catpv||| sv_catsv_flags||5.007002| sv_catsv_mg|5.004050||p sv_catsv_nomg|5.007002||p sv_catsv||| sv_chop||| sv_clean_all||| sv_clean_objs||| sv_clear||| sv_cmp_flags||5.013006| sv_cmp_locale_flags||5.013006| sv_cmp_locale||5.004000| sv_cmp||| sv_collxfrm_flags||5.013006| sv_collxfrm||| sv_copypv_flags||5.017002| sv_copypv_nomg||5.017002| sv_copypv||| sv_dec_nomg||5.013002| sv_dec||| sv_del_backref||| sv_derived_from_pvn||5.015004| sv_derived_from_pv||5.015004| sv_derived_from_sv||5.015004| sv_derived_from||5.004000| sv_destroyable||5.010000| sv_display||| sv_does_pvn||5.015004| sv_does_pv||5.015004| sv_does_sv||5.015004| sv_does||5.009004| sv_dump||| sv_dup_common||| sv_dup_inc_multiple||| sv_dup_inc||| sv_dup||| sv_eq_flags||5.013006| sv_eq||| sv_exp_grow||| sv_force_normal_flags||5.007001| sv_force_normal||5.006000| sv_free_arenas||| sv_free||| sv_gets||5.003070| sv_grow||| sv_i_ncmp||| sv_inc_nomg||5.013002| sv_inc||| sv_insert_flags||5.010001| sv_insert||| sv_isa||| sv_isobject||| sv_iv||5.005000| sv_len_utf8_nomg||| sv_len_utf8||5.006000| sv_len||| sv_magic_portable|5.024000|5.004000|p sv_magicext_mglob||| sv_magicext||5.007003| sv_magic||| sv_mortalcopy_flags||| sv_mortalcopy||| sv_ncmp||| sv_newmortal||| sv_newref||| sv_nolocking||5.007003| sv_nosharing||5.007003| sv_nounlocking||| sv_nv||5.005000| sv_only_taint_gmagic|||n sv_or_pv_pos_u2b||| sv_peek||5.005000| sv_pos_b2u_flags||5.019003| sv_pos_b2u_midway||| sv_pos_b2u||5.006000| sv_pos_u2b_cached||| sv_pos_u2b_flags||5.011005| sv_pos_u2b_forwards|||n sv_pos_u2b_midway|||n sv_pos_u2b||5.006000| sv_pvbyten_force||5.006000| sv_pvbyten||5.006000| sv_pvbyte||5.006000| sv_pvn_force_flags|5.007002||p sv_pvn_force||| sv_pvn_nomg|5.007003|5.005000|p sv_pvn||5.005000| sv_pvutf8n_force||5.006000| sv_pvutf8n||5.006000| sv_pvutf8||5.006000| sv_pv||5.006000| sv_recode_to_utf8||5.007003| sv_reftype||| sv_ref||5.015004| sv_replace||| sv_report_used||| sv_resetpvn||| sv_reset||| sv_rvweaken||5.006000| sv_sethek||| sv_setiv_mg|5.004050||p sv_setiv||| sv_setnv_mg|5.006000||p sv_setnv||| sv_setpv_mg|5.004050||p sv_setpvf_mg_nocontext|||pvn sv_setpvf_mg|5.006000|5.004000|pv sv_setpvf_nocontext|||vn sv_setpvf||5.004000|v sv_setpviv_mg||5.008001| sv_setpviv||5.008001| sv_setpvn_mg|5.004050||p sv_setpvn||| sv_setpvs_mg||5.013006| sv_setpvs|5.009004||p sv_setpv||| sv_setref_iv||| sv_setref_nv||| sv_setref_pvn||| sv_setref_pvs||5.024000| sv_setref_pv||| sv_setref_uv||5.007001| sv_setsv_flags||5.007002| sv_setsv_mg|5.004050||p sv_setsv_nomg|5.007002||p sv_setsv||| sv_setuv_mg|5.004050||p sv_setuv|5.004000||p sv_tainted||5.004000| sv_taint||5.004000| sv_true||5.005000| sv_unglob||| sv_uni_display||5.007003| sv_unmagicext|5.013008||p sv_unmagic||| sv_unref_flags||5.007001| sv_unref||| sv_untaint||5.004000| sv_upgrade||| sv_usepvn_flags||5.009004| sv_usepvn_mg|5.004050||p sv_usepvn||| sv_utf8_encode||5.006000| sv_utf8_upgrade_flags_grow||5.011000| sv_utf8_upgrade_flags||5.007002| sv_utf8_upgrade_nomg||5.007002| sv_utf8_upgrade||5.007001| sv_uv|5.005000||p sv_vcatpvf_mg|5.006000|5.004000|p sv_vcatpvfn_flags||5.017002| sv_vcatpvfn||5.004000| sv_vcatpvf|5.006000|5.004000|p sv_vsetpvf_mg|5.006000|5.004000|p sv_vsetpvfn||5.004000| sv_vsetpvf|5.006000|5.004000|p svtype||| swallow_bom||| swatch_get||| sync_locale||5.021004| sys_init3||5.010000|n sys_init||5.010000|n sys_intern_clear||| sys_intern_dup||| sys_intern_init||| sys_term||5.010000|n taint_env||| taint_proper||| tied_method|||v tmps_grow_p||| toFOLD_utf8||5.019001| toFOLD_uvchr||5.023009| toFOLD||5.019001| toLOWER_L1||5.019001| toLOWER_LC||5.004000| toLOWER_utf8||5.015007| toLOWER_uvchr||5.023009| toLOWER||| toTITLE_utf8||5.015007| toTITLE_uvchr||5.023009| toTITLE||5.019001| toUPPER_utf8||5.015007| toUPPER_uvchr||5.023009| toUPPER||| to_byte_substr||| to_lower_latin1|||n to_utf8_fold||5.015007| to_utf8_lower||5.015007| to_utf8_substr||| to_utf8_title||5.015007| to_utf8_upper||5.015007| tokenize_use||| tokeq||| tokereport||| too_few_arguments_pv||| too_many_arguments_pv||| translate_substr_offsets|||n try_amagic_bin||| try_amagic_un||| uiv_2buf|||n unlnk||| unpack_rec||| unpack_str||5.007003| unpackstring||5.008001| unreferenced_to_tmp_stack||| unshare_hek_or_pvn||| unshare_hek||| unsharepvn||5.003070| unwind_handler_stack||| update_debugger_info||| upg_version||5.009005| usage||| utf16_textfilter||| utf16_to_utf8_reversed||5.006001| utf16_to_utf8||5.006001| utf8_distance||5.006000| utf8_hop||5.006000|n utf8_length||5.007001| utf8_mg_len_cache_update||| utf8_mg_pos_cache_update||| utf8_to_uvchr_buf||5.015009| utf8n_to_uvchr||5.007001| utf8n_to_uvuni||5.007001| utilize||| uvchr_to_utf8_flags||5.007003| uvchr_to_utf8||5.007001| uvoffuni_to_utf8_flags||5.019004| uvuni_to_utf8_flags||5.007003| uvuni_to_utf8||5.007001| validate_suid||| varname||| vcmp||5.009000| vcroak||5.006000| vdeb||5.007003| vform||5.006000| visit||| vivify_defelem||| vivify_ref||| vload_module|5.006000||p vmess|5.006000|5.006000|p vnewSVpvf|5.006000|5.004000|p vnormal||5.009002| vnumify||5.009000| vstringify||5.009000| vverify||5.009003| vwarner||5.006000| vwarn||5.006000| wait4pid||| warn_nocontext|||pvn warn_sv|5.013001||p warner_nocontext|||vn warner|5.006000|5.004000|pv warn|||v was_lvalue_sub||| watch||| whichsig_pvn||5.015004| whichsig_pv||5.015004| whichsig_sv||5.015004| whichsig||| win32_croak_not_implemented|||n with_queued_errors||| wrap_op_checker||5.015008| write_to_stderr||| xs_boot_epilog||| xs_handshake|||vn xs_version_bootcheck||| yyerror_pvn||| yyerror_pv||| yyerror||| yylex||| yyparse||| yyunlex||| yywarn||| ); if (exists $opt{'list-unsupported'}) { my $f; for $f (sort { lc $a cmp lc $b } keys %API) { next unless $API{$f}{todo}; print "$f ", '.'x(40-length($f)), " ", format_version($API{$f}{todo}), "\n"; } exit 0; } # Scan for possible replacement candidates my(%replace, %need, %hints, %warnings, %depends); my $replace = 0; my($hint, $define, $function); sub find_api { my $code = shift; $code =~ s{ / (?: \*[^*]*\*+(?:[^$ccs][^*]*\*+)* / | /[^\r\n]*) | "[^"\\]*(?:\\.[^"\\]*)*" | '[^'\\]*(?:\\.[^'\\]*)*' }{}egsx; grep { exists $API{$_} } $code =~ /(\w+)/mg; } while () { if ($hint) { my $h = $hint->[0] eq 'Hint' ? \%hints : \%warnings; if (m{^\s*\*\s(.*?)\s*$}) { for (@{$hint->[1]}) { $h->{$_} ||= ''; # suppress warning with older perls $h->{$_} .= "$1\n"; } } else { undef $hint } } $hint = [$1, [split /,?\s+/, $2]] if m{^\s*$rccs\s+(Hint|Warning):\s+(\w+(?:,?\s+\w+)*)\s*$}; if ($define) { if ($define->[1] =~ /\\$/) { $define->[1] .= $_; } else { if (exists $API{$define->[0]} && $define->[1] !~ /^DPPP_\(/) { my @n = find_api($define->[1]); push @{$depends{$define->[0]}}, @n if @n } undef $define; } } $define = [$1, $2] if m{^\s*#\s*define\s+(\w+)(?:\([^)]*\))?\s+(.*)}; if ($function) { if (/^}/) { if (exists $API{$function->[0]}) { my @n = find_api($function->[1]); push @{$depends{$function->[0]}}, @n if @n } undef $function; } else { $function->[1] .= $_; } } $function = [$1, ''] if m{^DPPP_\(my_(\w+)\)}; $replace = $1 if m{^\s*$rccs\s+Replace:\s+(\d+)\s+$rcce\s*$}; $replace{$2} = $1 if $replace and m{^\s*#\s*define\s+(\w+)(?:\([^)]*\))?\s+(\w+)}; $replace{$2} = $1 if m{^\s*#\s*define\s+(\w+)(?:\([^)]*\))?\s+(\w+).*$rccs\s+Replace\s+$rcce}; $replace{$1} = $2 if m{^\s*$rccs\s+Replace (\w+) with (\w+)\s+$rcce\s*$}; if (m{^\s*$rccs\s+(\w+(\s*,\s*\w+)*)\s+depends\s+on\s+(\w+(\s*,\s*\w+)*)\s+$rcce\s*$}) { my @deps = map { s/\s+//g; $_ } split /,/, $3; my $d; for $d (map { s/\s+//g; $_ } split /,/, $1) { push @{$depends{$d}}, @deps; } } $need{$1} = 1 if m{^#if\s+defined\(NEED_(\w+)(?:_GLOBAL)?\)}; } for (values %depends) { my %s; $_ = [sort grep !$s{$_}++, @$_]; } if (exists $opt{'api-info'}) { my $f; my $count = 0; my $match = $opt{'api-info'} =~ m!^/(.*)/$! ? $1 : "^\Q$opt{'api-info'}\E\$"; for $f (sort { lc $a cmp lc $b } keys %API) { next unless $f =~ /$match/; print "\n=== $f ===\n\n"; my $info = 0; if ($API{$f}{base} || $API{$f}{todo}) { my $base = format_version($API{$f}{base} || $API{$f}{todo}); print "Supported at least starting from perl-$base.\n"; $info++; } if ($API{$f}{provided}) { my $todo = $API{$f}{todo} ? format_version($API{$f}{todo}) : "5.003"; print "Support by $ppport provided back to perl-$todo.\n"; print "Support needs to be explicitly requested by NEED_$f.\n" if exists $need{$f}; print "Depends on: ", join(', ', @{$depends{$f}}), ".\n" if exists $depends{$f}; print "\n$hints{$f}" if exists $hints{$f}; print "\nWARNING:\n$warnings{$f}" if exists $warnings{$f}; $info++; } print "No portability information available.\n" unless $info; $count++; } $count or print "Found no API matching '$opt{'api-info'}'."; print "\n"; exit 0; } if (exists $opt{'list-provided'}) { my $f; for $f (sort { lc $a cmp lc $b } keys %API) { next unless $API{$f}{provided}; my @flags; push @flags, 'explicit' if exists $need{$f}; push @flags, 'depend' if exists $depends{$f}; push @flags, 'hint' if exists $hints{$f}; push @flags, 'warning' if exists $warnings{$f}; my $flags = @flags ? ' ['.join(', ', @flags).']' : ''; print "$f$flags\n"; } exit 0; } my @files; my @srcext = qw( .xs .c .h .cc .cpp -c.inc -xs.inc ); my $srcext = join '|', map { quotemeta $_ } @srcext; if (@ARGV) { my %seen; for (@ARGV) { if (-e) { if (-f) { push @files, $_ unless $seen{$_}++; } else { warn "'$_' is not a file.\n" } } else { my @new = grep { -f } glob $_ or warn "'$_' does not exist.\n"; push @files, grep { !$seen{$_}++ } @new; } } } else { eval { require File::Find; File::Find::find(sub { $File::Find::name =~ /($srcext)$/i and push @files, $File::Find::name; }, '.'); }; if ($@) { @files = map { glob "*$_" } @srcext; } } if (!@ARGV || $opt{filter}) { my(@in, @out); my %xsc = map { /(.*)\.xs$/ ? ("$1.c" => 1, "$1.cc" => 1) : () } @files; for (@files) { my $out = exists $xsc{$_} || /\b\Q$ppport\E$/i || !/($srcext)$/i; push @{ $out ? \@out : \@in }, $_; } if (@ARGV && @out) { warning("Skipping the following files (use --nofilter to avoid this):\n| ", join "\n| ", @out); } @files = @in; } die "No input files given!\n" unless @files; my(%files, %global, %revreplace); %revreplace = reverse %replace; my $filename; my $patch_opened = 0; for $filename (@files) { unless (open IN, "<$filename") { warn "Unable to read from $filename: $!\n"; next; } info("Scanning $filename ..."); my $c = do { local $/; }; close IN; my %file = (orig => $c, changes => 0); # Temporarily remove C/XS comments and strings from the code my @ccom; $c =~ s{ ( ^$HS*\#$HS*include\b[^\r\n]+\b(?:\Q$ppport\E|XSUB\.h)\b[^\r\n]* | ^$HS*\#$HS*(?:define|elif|if(?:def)?)\b[^\r\n]* ) | ( ^$HS*\#[^\r\n]* | "[^"\\]*(?:\\.[^"\\]*)*" | '[^'\\]*(?:\\.[^'\\]*)*' | / (?: \*[^*]*\*+(?:[^$ccs][^*]*\*+)* / | /[^\r\n]* ) ) }{ defined $2 and push @ccom, $2; defined $1 ? $1 : "$ccs$#ccom$cce" }mgsex; $file{ccom} = \@ccom; $file{code} = $c; $file{has_inc_ppport} = $c =~ /^$HS*#$HS*include[^\r\n]+\b\Q$ppport\E\b/m; my $func; for $func (keys %API) { my $match = $func; $match .= "|$revreplace{$func}" if exists $revreplace{$func}; if ($c =~ /\b(?:Perl_)?($match)\b/) { $file{uses_replace}{$1}++ if exists $revreplace{$func} && $1 eq $revreplace{$func}; $file{uses_Perl}{$func}++ if $c =~ /\bPerl_$func\b/; if (exists $API{$func}{provided}) { $file{uses_provided}{$func}++; if (!exists $API{$func}{base} || $API{$func}{base} > $opt{'compat-version'}) { $file{uses}{$func}++; my @deps = rec_depend($func); if (@deps) { $file{uses_deps}{$func} = \@deps; for (@deps) { $file{uses}{$_} = 0 unless exists $file{uses}{$_}; } } for ($func, @deps) { $file{needs}{$_} = 'static' if exists $need{$_}; } } } if (exists $API{$func}{todo} && $API{$func}{todo} > $opt{'compat-version'}) { if ($c =~ /\b$func\b/) { $file{uses_todo}{$func}++; } } } } while ($c =~ /^$HS*#$HS*define$HS+(NEED_(\w+?)(_GLOBAL)?)\b/mg) { if (exists $need{$2}) { $file{defined $3 ? 'needed_global' : 'needed_static'}{$2}++; } else { warning("Possibly wrong #define $1 in $filename") } } for (qw(uses needs uses_todo needed_global needed_static)) { for $func (keys %{$file{$_}}) { push @{$global{$_}{$func}}, $filename; } } $files{$filename} = \%file; } # Globally resolve NEED_'s my $need; for $need (keys %{$global{needs}}) { if (@{$global{needs}{$need}} > 1) { my @targets = @{$global{needs}{$need}}; my @t = grep $files{$_}{needed_global}{$need}, @targets; @targets = @t if @t; @t = grep /\.xs$/i, @targets; @targets = @t if @t; my $target = shift @targets; $files{$target}{needs}{$need} = 'global'; for (@{$global{needs}{$need}}) { $files{$_}{needs}{$need} = 'extern' if $_ ne $target; } } } for $filename (@files) { exists $files{$filename} or next; info("=== Analyzing $filename ==="); my %file = %{$files{$filename}}; my $func; my $c = $file{code}; my $warnings = 0; for $func (sort keys %{$file{uses_Perl}}) { if ($API{$func}{varargs}) { unless ($API{$func}{nothxarg}) { my $changes = ($c =~ s{\b(Perl_$func\s*\(\s*)(?!aTHX_?)(\)|[^\s)]*\))} { $1 . ($2 eq ')' ? 'aTHX' : 'aTHX_ ') . $2 }ge); if ($changes) { warning("Doesn't pass interpreter argument aTHX to Perl_$func"); $file{changes} += $changes; } } } else { warning("Uses Perl_$func instead of $func"); $file{changes} += ($c =~ s{\bPerl_$func(\s*)\((\s*aTHX_?)?\s*} {$func$1(}g); } } for $func (sort keys %{$file{uses_replace}}) { warning("Uses $func instead of $replace{$func}"); $file{changes} += ($c =~ s/\b$func\b/$replace{$func}/g); } for $func (sort keys %{$file{uses_provided}}) { if ($file{uses}{$func}) { if (exists $file{uses_deps}{$func}) { diag("Uses $func, which depends on ", join(', ', @{$file{uses_deps}{$func}})); } else { diag("Uses $func"); } } $warnings += hint($func); } unless ($opt{quiet}) { for $func (sort keys %{$file{uses_todo}}) { print "*** WARNING: Uses $func, which may not be portable below perl ", format_version($API{$func}{todo}), ", even with '$ppport'\n"; $warnings++; } } for $func (sort keys %{$file{needed_static}}) { my $message = ''; if (not exists $file{uses}{$func}) { $message = "No need to define NEED_$func if $func is never used"; } elsif (exists $file{needs}{$func} && $file{needs}{$func} ne 'static') { $message = "No need to define NEED_$func when already needed globally"; } if ($message) { diag($message); $file{changes} += ($c =~ s/^$HS*#$HS*define$HS+NEED_$func\b.*$LF//mg); } } for $func (sort keys %{$file{needed_global}}) { my $message = ''; if (not exists $global{uses}{$func}) { $message = "No need to define NEED_${func}_GLOBAL if $func is never used"; } elsif (exists $file{needs}{$func}) { if ($file{needs}{$func} eq 'extern') { $message = "No need to define NEED_${func}_GLOBAL when already needed globally"; } elsif ($file{needs}{$func} eq 'static') { $message = "No need to define NEED_${func}_GLOBAL when only used in this file"; } } if ($message) { diag($message); $file{changes} += ($c =~ s/^$HS*#$HS*define$HS+NEED_${func}_GLOBAL\b.*$LF//mg); } } $file{needs_inc_ppport} = keys %{$file{uses}}; if ($file{needs_inc_ppport}) { my $pp = ''; for $func (sort keys %{$file{needs}}) { my $type = $file{needs}{$func}; next if $type eq 'extern'; my $suffix = $type eq 'global' ? '_GLOBAL' : ''; unless (exists $file{"needed_$type"}{$func}) { if ($type eq 'global') { diag("Files [@{$global{needs}{$func}}] need $func, adding global request"); } else { diag("File needs $func, adding static request"); } $pp .= "#define NEED_$func$suffix\n"; } } if ($pp && ($c =~ s/^(?=$HS*#$HS*define$HS+NEED_\w+)/$pp/m)) { $pp = ''; $file{changes}++; } unless ($file{has_inc_ppport}) { diag("Needs to include '$ppport'"); $pp .= qq(#include "$ppport"\n) } if ($pp) { $file{changes} += ($c =~ s/^($HS*#$HS*define$HS+NEED_\w+.*?)^/$1$pp/ms) || ($c =~ s/^(?=$HS*#$HS*include.*\Q$ppport\E)/$pp/m) || ($c =~ s/^($HS*#$HS*include.*XSUB.*\s*?)^/$1$pp/m) || ($c =~ s/^/$pp/); } } else { if ($file{has_inc_ppport}) { diag("No need to include '$ppport'"); $file{changes} += ($c =~ s/^$HS*?#$HS*include.*\Q$ppport\E.*?$LF//m); } } # put back in our C comments my $ix; my $cppc = 0; my @ccom = @{$file{ccom}}; for $ix (0 .. $#ccom) { if (!$opt{cplusplus} && $ccom[$ix] =~ s!^//!!) { $cppc++; $file{changes} += $c =~ s/$rccs$ix$rcce/$ccs$ccom[$ix] $cce/; } else { $c =~ s/$rccs$ix$rcce/$ccom[$ix]/; } } if ($cppc) { my $s = $cppc != 1 ? 's' : ''; warning("Uses $cppc C++ style comment$s, which is not portable"); } my $s = $warnings != 1 ? 's' : ''; my $warn = $warnings ? " ($warnings warning$s)" : ''; info("Analysis completed$warn"); if ($file{changes}) { if (exists $opt{copy}) { my $newfile = "$filename$opt{copy}"; if (-e $newfile) { error("'$newfile' already exists, refusing to write copy of '$filename'"); } else { local *F; if (open F, ">$newfile") { info("Writing copy of '$filename' with changes to '$newfile'"); print F $c; close F; } else { error("Cannot open '$newfile' for writing: $!"); } } } elsif (exists $opt{patch} || $opt{changes}) { if (exists $opt{patch}) { unless ($patch_opened) { if (open PATCH, ">$opt{patch}") { $patch_opened = 1; } else { error("Cannot open '$opt{patch}' for writing: $!"); delete $opt{patch}; $opt{changes} = 1; goto fallback; } } mydiff(\*PATCH, $filename, $c); } else { fallback: info("Suggested changes:"); mydiff(\*STDOUT, $filename, $c); } } else { my $s = $file{changes} == 1 ? '' : 's'; info("$file{changes} potentially required change$s detected"); } } else { info("Looks good"); } } close PATCH if $patch_opened; exit 0; sub try_use { eval "use @_;"; return $@ eq '' } sub mydiff { local *F = shift; my($file, $str) = @_; my $diff; if (exists $opt{diff}) { $diff = run_diff($opt{diff}, $file, $str); } if (!defined $diff and try_use('Text::Diff')) { $diff = Text::Diff::diff($file, \$str, { STYLE => 'Unified' }); $diff = <
$tmp") { print F $str; close F; if (open F, "$prog $file $tmp |") { while () { s/\Q$tmp\E/$file.patched/; $diff .= $_; } close F; unlink $tmp; return $diff; } unlink $tmp; } else { error("Cannot open '$tmp' for writing: $!"); } return undef; } sub rec_depend { my($func, $seen) = @_; return () unless exists $depends{$func}; $seen = {%{$seen||{}}}; return () if $seen->{$func}++; my %s; grep !$s{$_}++, map { ($_, rec_depend($_, $seen)) } @{$depends{$func}}; } sub parse_version { my $ver = shift; if ($ver =~ /^(\d+)\.(\d+)\.(\d+)$/) { return ($1, $2, $3); } elsif ($ver !~ /^\d+\.[\d_]+$/) { die "cannot parse version '$ver'\n"; } $ver =~ s/_//g; $ver =~ s/$/000000/; my($r,$v,$s) = $ver =~ /(\d+)\.(\d{3})(\d{3})/; $v = int $v; $s = int $s; if ($r < 5 || ($r == 5 && $v < 6)) { if ($s % 10) { die "cannot parse version '$ver'\n"; } } return ($r, $v, $s); } sub format_version { my $ver = shift; $ver =~ s/$/000000/; my($r,$v,$s) = $ver =~ /(\d+)\.(\d{3})(\d{3})/; $v = int $v; $s = int $s; if ($r < 5 || ($r == 5 && $v < 6)) { if ($s % 10) { die "invalid version '$ver'\n"; } $s /= 10; $ver = sprintf "%d.%03d", $r, $v; $s > 0 and $ver .= sprintf "_%02d", $s; return $ver; } return sprintf "%d.%d.%d", $r, $v, $s; } sub info { $opt{quiet} and return; print @_, "\n"; } sub diag { $opt{quiet} and return; $opt{diag} and print @_, "\n"; } sub warning { $opt{quiet} and return; print "*** ", @_, "\n"; } sub error { print "*** ERROR: ", @_, "\n"; } my %given_hints; my %given_warnings; sub hint { $opt{quiet} and return; my $func = shift; my $rv = 0; if (exists $warnings{$func} && !$given_warnings{$func}++) { my $warn = $warnings{$func}; $warn =~ s!^!*** !mg; print "*** WARNING: $func\n", $warn; $rv++; } if ($opt{hints} && exists $hints{$func} && !$given_hints{$func}++) { my $hint = $hints{$func}; $hint =~ s/^/ /mg; print " --- hint for $func ---\n", $hint; } $rv; } sub usage { my($usage) = do { local(@ARGV,$/)=($0); <> } =~ /^=head\d$HS+SYNOPSIS\s*^(.*?)\s*^=/ms; my %M = ( 'I' => '*' ); $usage =~ s/^\s*perl\s+\S+/$^X $0/; $usage =~ s/([A-Z])<([^>]+)>/$M{$1}$2$M{$1}/g; print < }; my($copy) = $self =~ /^=head\d\s+COPYRIGHT\s*^(.*?)^=\w+/ms; $copy =~ s/^(?=\S+)/ /gms; $self =~ s/^$HS+Do NOT edit.*?(?=^-)/$copy/ms; $self =~ s/^SKIP.*(?=^__DATA__)/SKIP if (\@ARGV && \$ARGV[0] eq '--unstrip') { eval { require Devel::PPPort }; \$@ and die "Cannot require Devel::PPPort, please install.\\n"; if (eval \$Devel::PPPort::VERSION < $VERSION) { die "$0 was originally generated with Devel::PPPort $VERSION.\\n" . "Your Devel::PPPort is only version \$Devel::PPPort::VERSION.\\n" . "Please install a newer version, or --unstrip will not work.\\n"; } Devel::PPPort::WriteFile(\$0); exit 0; } print <$0" or die "cannot strip $0: $!\n"; print OUT "$pl$c\n"; exit 0; } __DATA__ */ #ifndef _P_P_PORTABILITY_H_ #define _P_P_PORTABILITY_H_ #ifndef DPPP_NAMESPACE # define DPPP_NAMESPACE DPPP_ #endif #define DPPP_CAT2(x,y) CAT2(x,y) #define DPPP_(name) DPPP_CAT2(DPPP_NAMESPACE, name) #ifndef PERL_REVISION # if !defined(__PATCHLEVEL_H_INCLUDED__) && !(defined(PATCHLEVEL) && defined(SUBVERSION)) # define PERL_PATCHLEVEL_H_IMPLICIT # include # endif # if !(defined(PERL_VERSION) || (defined(SUBVERSION) && defined(PATCHLEVEL))) # include # endif # ifndef PERL_REVISION # define PERL_REVISION (5) /* Replace: 1 */ # define PERL_VERSION PATCHLEVEL # define PERL_SUBVERSION SUBVERSION /* Replace PERL_PATCHLEVEL with PERL_VERSION */ /* Replace: 0 */ # endif #endif #define D_PPP_DEC2BCD(dec) ((((dec)/100)<<8)|((((dec)%100)/10)<<4)|((dec)%10)) #define PERL_BCDVERSION ((D_PPP_DEC2BCD(PERL_REVISION)<<24)|(D_PPP_DEC2BCD(PERL_VERSION)<<12)|D_PPP_DEC2BCD(PERL_SUBVERSION)) /* It is very unlikely that anyone will try to use this with Perl 6 (or greater), but who knows. */ #if PERL_REVISION != 5 # error c/ppport.h only works with Perl version 5 #endif /* PERL_REVISION != 5 */ #ifndef dTHR # define dTHR dNOOP #endif #ifndef dTHX # define dTHX dNOOP #endif #ifndef dTHXa # define dTHXa(x) dNOOP #endif #ifndef pTHX # define pTHX void #endif #ifndef pTHX_ # define pTHX_ #endif #ifndef aTHX # define aTHX #endif #ifndef aTHX_ # define aTHX_ #endif #if (PERL_BCDVERSION < 0x5006000) # ifdef USE_THREADS # define aTHXR thr # define aTHXR_ thr, # else # define aTHXR # define aTHXR_ # endif # define dTHXR dTHR #else # define aTHXR aTHX # define aTHXR_ aTHX_ # define dTHXR dTHX #endif #ifndef dTHXoa # define dTHXoa(x) dTHXa(x) #endif #ifdef I_LIMITS # include #endif #ifndef PERL_UCHAR_MIN # define PERL_UCHAR_MIN ((unsigned char)0) #endif #ifndef PERL_UCHAR_MAX # ifdef UCHAR_MAX # define PERL_UCHAR_MAX ((unsigned char)UCHAR_MAX) # else # ifdef MAXUCHAR # define PERL_UCHAR_MAX ((unsigned char)MAXUCHAR) # else # define PERL_UCHAR_MAX ((unsigned char)~(unsigned)0) # endif # endif #endif #ifndef PERL_USHORT_MIN # define PERL_USHORT_MIN ((unsigned short)0) #endif #ifndef PERL_USHORT_MAX # ifdef USHORT_MAX # define PERL_USHORT_MAX ((unsigned short)USHORT_MAX) # else # ifdef MAXUSHORT # define PERL_USHORT_MAX ((unsigned short)MAXUSHORT) # else # ifdef USHRT_MAX # define PERL_USHORT_MAX ((unsigned short)USHRT_MAX) # else # define PERL_USHORT_MAX ((unsigned short)~(unsigned)0) # endif # endif # endif #endif #ifndef PERL_SHORT_MAX # ifdef SHORT_MAX # define PERL_SHORT_MAX ((short)SHORT_MAX) # else # ifdef MAXSHORT /* Often used in */ # define PERL_SHORT_MAX ((short)MAXSHORT) # else # ifdef SHRT_MAX # define PERL_SHORT_MAX ((short)SHRT_MAX) # else # define PERL_SHORT_MAX ((short) (PERL_USHORT_MAX >> 1)) # endif # endif # endif #endif #ifndef PERL_SHORT_MIN # ifdef SHORT_MIN # define PERL_SHORT_MIN ((short)SHORT_MIN) # else # ifdef MINSHORT # define PERL_SHORT_MIN ((short)MINSHORT) # else # ifdef SHRT_MIN # define PERL_SHORT_MIN ((short)SHRT_MIN) # else # define PERL_SHORT_MIN (-PERL_SHORT_MAX - ((3 & -1) == 3)) # endif # endif # endif #endif #ifndef PERL_UINT_MAX # ifdef UINT_MAX # define PERL_UINT_MAX ((unsigned int)UINT_MAX) # else # ifdef MAXUINT # define PERL_UINT_MAX ((unsigned int)MAXUINT) # else # define PERL_UINT_MAX (~(unsigned int)0) # endif # endif #endif #ifndef PERL_UINT_MIN # define PERL_UINT_MIN ((unsigned int)0) #endif #ifndef PERL_INT_MAX # ifdef INT_MAX # define PERL_INT_MAX ((int)INT_MAX) # else # ifdef MAXINT /* Often used in */ # define PERL_INT_MAX ((int)MAXINT) # else # define PERL_INT_MAX ((int)(PERL_UINT_MAX >> 1)) # endif # endif #endif #ifndef PERL_INT_MIN # ifdef INT_MIN # define PERL_INT_MIN ((int)INT_MIN) # else # ifdef MININT # define PERL_INT_MIN ((int)MININT) # else # define PERL_INT_MIN (-PERL_INT_MAX - ((3 & -1) == 3)) # endif # endif #endif #ifndef PERL_ULONG_MAX # ifdef ULONG_MAX # define PERL_ULONG_MAX ((unsigned long)ULONG_MAX) # else # ifdef MAXULONG # define PERL_ULONG_MAX ((unsigned long)MAXULONG) # else # define PERL_ULONG_MAX (~(unsigned long)0) # endif # endif #endif #ifndef PERL_ULONG_MIN # define PERL_ULONG_MIN ((unsigned long)0L) #endif #ifndef PERL_LONG_MAX # ifdef LONG_MAX # define PERL_LONG_MAX ((long)LONG_MAX) # else # ifdef MAXLONG # define PERL_LONG_MAX ((long)MAXLONG) # else # define PERL_LONG_MAX ((long) (PERL_ULONG_MAX >> 1)) # endif # endif #endif #ifndef PERL_LONG_MIN # ifdef LONG_MIN # define PERL_LONG_MIN ((long)LONG_MIN) # else # ifdef MINLONG # define PERL_LONG_MIN ((long)MINLONG) # else # define PERL_LONG_MIN (-PERL_LONG_MAX - ((3 & -1) == 3)) # endif # endif #endif #if defined(HAS_QUAD) && (defined(convex) || defined(uts)) # ifndef PERL_UQUAD_MAX # ifdef ULONGLONG_MAX # define PERL_UQUAD_MAX ((unsigned long long)ULONGLONG_MAX) # else # ifdef MAXULONGLONG # define PERL_UQUAD_MAX ((unsigned long long)MAXULONGLONG) # else # define PERL_UQUAD_MAX (~(unsigned long long)0) # endif # endif # endif # ifndef PERL_UQUAD_MIN # define PERL_UQUAD_MIN ((unsigned long long)0L) # endif # ifndef PERL_QUAD_MAX # ifdef LONGLONG_MAX # define PERL_QUAD_MAX ((long long)LONGLONG_MAX) # else # ifdef MAXLONGLONG # define PERL_QUAD_MAX ((long long)MAXLONGLONG) # else # define PERL_QUAD_MAX ((long long) (PERL_UQUAD_MAX >> 1)) # endif # endif # endif # ifndef PERL_QUAD_MIN # ifdef LONGLONG_MIN # define PERL_QUAD_MIN ((long long)LONGLONG_MIN) # else # ifdef MINLONGLONG # define PERL_QUAD_MIN ((long long)MINLONGLONG) # else # define PERL_QUAD_MIN (-PERL_QUAD_MAX - ((3 & -1) == 3)) # endif # endif # endif #endif /* This is based on code from 5.003 perl.h */ #ifdef HAS_QUAD # ifdef cray #ifndef IVTYPE # define IVTYPE int #endif #ifndef IV_MIN # define IV_MIN PERL_INT_MIN #endif #ifndef IV_MAX # define IV_MAX PERL_INT_MAX #endif #ifndef UV_MIN # define UV_MIN PERL_UINT_MIN #endif #ifndef UV_MAX # define UV_MAX PERL_UINT_MAX #endif # ifdef INTSIZE #ifndef IVSIZE # define IVSIZE INTSIZE #endif # endif # else # if defined(convex) || defined(uts) #ifndef IVTYPE # define IVTYPE long long #endif #ifndef IV_MIN # define IV_MIN PERL_QUAD_MIN #endif #ifndef IV_MAX # define IV_MAX PERL_QUAD_MAX #endif #ifndef UV_MIN # define UV_MIN PERL_UQUAD_MIN #endif #ifndef UV_MAX # define UV_MAX PERL_UQUAD_MAX #endif # ifdef LONGLONGSIZE #ifndef IVSIZE # define IVSIZE LONGLONGSIZE #endif # endif # else #ifndef IVTYPE # define IVTYPE long #endif #ifndef IV_MIN # define IV_MIN PERL_LONG_MIN #endif #ifndef IV_MAX # define IV_MAX PERL_LONG_MAX #endif #ifndef UV_MIN # define UV_MIN PERL_ULONG_MIN #endif #ifndef UV_MAX # define UV_MAX PERL_ULONG_MAX #endif # ifdef LONGSIZE #ifndef IVSIZE # define IVSIZE LONGSIZE #endif # endif # endif # endif #ifndef IVSIZE # define IVSIZE 8 #endif #ifndef LONGSIZE # define LONGSIZE 8 #endif #ifndef PERL_QUAD_MIN # define PERL_QUAD_MIN IV_MIN #endif #ifndef PERL_QUAD_MAX # define PERL_QUAD_MAX IV_MAX #endif #ifndef PERL_UQUAD_MIN # define PERL_UQUAD_MIN UV_MIN #endif #ifndef PERL_UQUAD_MAX # define PERL_UQUAD_MAX UV_MAX #endif #else #ifndef IVTYPE # define IVTYPE long #endif #ifndef LONGSIZE # define LONGSIZE 4 #endif #ifndef IV_MIN # define IV_MIN PERL_LONG_MIN #endif #ifndef IV_MAX # define IV_MAX PERL_LONG_MAX #endif #ifndef UV_MIN # define UV_MIN PERL_ULONG_MIN #endif #ifndef UV_MAX # define UV_MAX PERL_ULONG_MAX #endif #endif #ifndef IVSIZE # ifdef LONGSIZE # define IVSIZE LONGSIZE # else # define IVSIZE 4 /* A bold guess, but the best we can make. */ # endif #endif #ifndef UVTYPE # define UVTYPE unsigned IVTYPE #endif #ifndef UVSIZE # define UVSIZE IVSIZE #endif #ifndef sv_setuv # define sv_setuv(sv, uv) \ STMT_START { \ UV TeMpUv = uv; \ if (TeMpUv <= IV_MAX) \ sv_setiv(sv, TeMpUv); \ else \ sv_setnv(sv, (double)TeMpUv); \ } STMT_END #endif #ifndef newSVuv # define newSVuv(uv) ((uv) <= IV_MAX ? newSViv((IV)uv) : newSVnv((NV)uv)) #endif #ifndef sv_2uv # define sv_2uv(sv) ((PL_Sv = (sv)), (UV) (SvNOK(PL_Sv) ? SvNV(PL_Sv) : sv_2nv(PL_Sv))) #endif #ifndef SvUVX # define SvUVX(sv) ((UV)SvIVX(sv)) #endif #ifndef SvUVXx # define SvUVXx(sv) SvUVX(sv) #endif #ifndef SvUV # define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv)) #endif #ifndef SvUVx # define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv)) #endif /* Hint: sv_uv * Always use the SvUVx() macro instead of sv_uv(). */ #ifndef sv_uv # define sv_uv(sv) SvUVx(sv) #endif #if !defined(SvUOK) && defined(SvIOK_UV) # define SvUOK(sv) SvIOK_UV(sv) #endif #ifndef XST_mUV # define XST_mUV(i,v) (ST(i) = sv_2mortal(newSVuv(v)) ) #endif #ifndef XSRETURN_UV # define XSRETURN_UV(v) STMT_START { XST_mUV(0,v); XSRETURN(1); } STMT_END #endif #ifndef PUSHu # define PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END #endif #ifndef XPUSHu # define XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END #endif #ifdef HAS_MEMCMP #ifndef memNE # define memNE(s1,s2,l) (memcmp(s1,s2,l)) #endif #ifndef memEQ # define memEQ(s1,s2,l) (!memcmp(s1,s2,l)) #endif #else #ifndef memNE # define memNE(s1,s2,l) (bcmp(s1,s2,l)) #endif #ifndef memEQ # define memEQ(s1,s2,l) (!bcmp(s1,s2,l)) #endif #endif #ifndef memEQs # define memEQs(s1, l, s2) \ (sizeof(s2)-1 == l && memEQ(s1, (s2 ""), (sizeof(s2)-1))) #endif #ifndef memNEs # define memNEs(s1, l, s2) !memEQs(s1, l, s2) #endif #ifndef MoveD # define MoveD(s,d,n,t) memmove((char*)(d),(char*)(s), (n) * sizeof(t)) #endif #ifndef CopyD # define CopyD(s,d,n,t) memcpy((char*)(d),(char*)(s), (n) * sizeof(t)) #endif #ifdef HAS_MEMSET #ifndef ZeroD # define ZeroD(d,n,t) memzero((char*)(d), (n) * sizeof(t)) #endif #else #ifndef ZeroD # define ZeroD(d,n,t) ((void)memzero((char*)(d), (n) * sizeof(t)), d) #endif #endif #ifndef PoisonWith # define PoisonWith(d,n,t,b) (void)memset((char*)(d), (U8)(b), (n) * sizeof(t)) #endif #ifndef PoisonNew # define PoisonNew(d,n,t) PoisonWith(d,n,t,0xAB) #endif #ifndef PoisonFree # define PoisonFree(d,n,t) PoisonWith(d,n,t,0xEF) #endif #ifndef Poison # define Poison(d,n,t) PoisonFree(d,n,t) #endif #ifndef Newx # define Newx(v,n,t) New(0,v,n,t) #endif #ifndef Newxc # define Newxc(v,n,t,c) Newc(0,v,n,t,c) #endif #ifndef Newxz # define Newxz(v,n,t) Newz(0,v,n,t) #endif #ifndef PERL_MAGIC_sv # define PERL_MAGIC_sv '\0' #endif #ifndef PERL_MAGIC_overload # define PERL_MAGIC_overload 'A' #endif #ifndef PERL_MAGIC_overload_elem # define PERL_MAGIC_overload_elem 'a' #endif #ifndef PERL_MAGIC_overload_table # define PERL_MAGIC_overload_table 'c' #endif #ifndef PERL_MAGIC_bm # define PERL_MAGIC_bm 'B' #endif #ifndef PERL_MAGIC_regdata # define PERL_MAGIC_regdata 'D' #endif #ifndef PERL_MAGIC_regdatum # define PERL_MAGIC_regdatum 'd' #endif #ifndef PERL_MAGIC_env # define PERL_MAGIC_env 'E' #endif #ifndef PERL_MAGIC_envelem # define PERL_MAGIC_envelem 'e' #endif #ifndef PERL_MAGIC_fm # define PERL_MAGIC_fm 'f' #endif #ifndef PERL_MAGIC_regex_global # define PERL_MAGIC_regex_global 'g' #endif #ifndef PERL_MAGIC_isa # define PERL_MAGIC_isa 'I' #endif #ifndef PERL_MAGIC_isaelem # define PERL_MAGIC_isaelem 'i' #endif #ifndef PERL_MAGIC_nkeys # define PERL_MAGIC_nkeys 'k' #endif #ifndef PERL_MAGIC_dbfile # define PERL_MAGIC_dbfile 'L' #endif #ifndef PERL_MAGIC_dbline # define PERL_MAGIC_dbline 'l' #endif #ifndef PERL_MAGIC_mutex # define PERL_MAGIC_mutex 'm' #endif #ifndef PERL_MAGIC_shared # define PERL_MAGIC_shared 'N' #endif #ifndef PERL_MAGIC_shared_scalar # define PERL_MAGIC_shared_scalar 'n' #endif #ifndef PERL_MAGIC_collxfrm # define PERL_MAGIC_collxfrm 'o' #endif #ifndef PERL_MAGIC_tied # define PERL_MAGIC_tied 'P' #endif #ifndef PERL_MAGIC_tiedelem # define PERL_MAGIC_tiedelem 'p' #endif #ifndef PERL_MAGIC_tiedscalar # define PERL_MAGIC_tiedscalar 'q' #endif #ifndef PERL_MAGIC_qr # define PERL_MAGIC_qr 'r' #endif #ifndef PERL_MAGIC_sig # define PERL_MAGIC_sig 'S' #endif #ifndef PERL_MAGIC_sigelem # define PERL_MAGIC_sigelem 's' #endif #ifndef PERL_MAGIC_taint # define PERL_MAGIC_taint 't' #endif #ifndef PERL_MAGIC_uvar # define PERL_MAGIC_uvar 'U' #endif #ifndef PERL_MAGIC_uvar_elem # define PERL_MAGIC_uvar_elem 'u' #endif #ifndef PERL_MAGIC_vstring # define PERL_MAGIC_vstring 'V' #endif #ifndef PERL_MAGIC_vec # define PERL_MAGIC_vec 'v' #endif #ifndef PERL_MAGIC_utf8 # define PERL_MAGIC_utf8 'w' #endif #ifndef PERL_MAGIC_substr # define PERL_MAGIC_substr 'x' #endif #ifndef PERL_MAGIC_defelem # define PERL_MAGIC_defelem 'y' #endif #ifndef PERL_MAGIC_glob # define PERL_MAGIC_glob '*' #endif #ifndef PERL_MAGIC_arylen # define PERL_MAGIC_arylen '#' #endif #ifndef PERL_MAGIC_pos # define PERL_MAGIC_pos '.' #endif #ifndef PERL_MAGIC_backref # define PERL_MAGIC_backref '<' #endif #ifndef PERL_MAGIC_ext # define PERL_MAGIC_ext '~' #endif #ifndef cBOOL # define cBOOL(cbool) ((cbool) ? (bool)1 : (bool)0) #endif #ifndef OpHAS_SIBLING # define OpHAS_SIBLING(o) (cBOOL((o)->op_sibling)) #endif #ifndef OpSIBLING # define OpSIBLING(o) (0 + (o)->op_sibling) #endif #ifndef OpMORESIB_set # define OpMORESIB_set(o, sib) ((o)->op_sibling = (sib)) #endif #ifndef OpLASTSIB_set # define OpLASTSIB_set(o, parent) ((o)->op_sibling = NULL) #endif #ifndef OpMAYBESIB_set # define OpMAYBESIB_set(o, sib, parent) ((o)->op_sibling = (sib)) #endif #ifndef HEf_SVKEY # define HEf_SVKEY -2 #endif #ifndef SvRX #if defined(NEED_SvRX) static void * DPPP_(my_SvRX)(pTHX_ SV *rv); static #else extern void * DPPP_(my_SvRX)(pTHX_ SV *rv); #endif #if defined(NEED_SvRX) || defined(NEED_SvRX_GLOBAL) #ifdef SvRX # undef SvRX #endif #define SvRX(a) DPPP_(my_SvRX)(aTHX_ a) void * DPPP_(my_SvRX)(pTHX_ SV *rv) { if (SvROK(rv)) { SV *sv = SvRV(rv); if (SvMAGICAL(sv)) { MAGIC *mg = mg_find(sv, PERL_MAGIC_qr); if (mg && mg->mg_obj) { return mg->mg_obj; } } } return 0; } #endif #endif #ifndef SvRXOK # define SvRXOK(sv) (!!SvRX(sv)) #endif #ifndef PERL_UNUSED_DECL # ifdef HASATTRIBUTE # if (defined(__GNUC__) && defined(__cplusplus)) || defined(__INTEL_COMPILER) # define PERL_UNUSED_DECL # else # define PERL_UNUSED_DECL __attribute__((unused)) # endif # else # define PERL_UNUSED_DECL # endif #endif #ifndef PERL_UNUSED_ARG # if defined(lint) && defined(S_SPLINT_S) /* www.splint.org */ # include # define PERL_UNUSED_ARG(x) NOTE(ARGUNUSED(x)) # else # define PERL_UNUSED_ARG(x) ((void)x) # endif #endif #ifndef PERL_UNUSED_VAR # define PERL_UNUSED_VAR(x) ((void)x) #endif #ifndef PERL_UNUSED_CONTEXT # ifdef USE_ITHREADS # define PERL_UNUSED_CONTEXT PERL_UNUSED_ARG(my_perl) # else # define PERL_UNUSED_CONTEXT # endif #endif #ifndef PERL_UNUSED_RESULT # if defined(__GNUC__) && defined(HASATTRIBUTE_WARN_UNUSED_RESULT) # define PERL_UNUSED_RESULT(v) STMT_START { __typeof__(v) z = (v); (void)sizeof(z); } STMT_END # else # define PERL_UNUSED_RESULT(v) ((void)(v)) # endif #endif #ifndef NOOP # define NOOP /*EMPTY*/(void)0 #endif #ifndef dNOOP # define dNOOP extern int /*@unused@*/ Perl___notused PERL_UNUSED_DECL #endif #ifndef NVTYPE # if defined(USE_LONG_DOUBLE) && defined(HAS_LONG_DOUBLE) # define NVTYPE long double # else # define NVTYPE double # endif typedef NVTYPE NV; #endif #ifndef INT2PTR # if (IVSIZE == PTRSIZE) && (UVSIZE == PTRSIZE) # define PTRV UV # define INT2PTR(any,d) (any)(d) # else # if PTRSIZE == LONGSIZE # define PTRV unsigned long # else # define PTRV unsigned # endif # define INT2PTR(any,d) (any)(PTRV)(d) # endif #endif #ifndef PTR2ul # if PTRSIZE == LONGSIZE # define PTR2ul(p) (unsigned long)(p) # else # define PTR2ul(p) INT2PTR(unsigned long,p) # endif #endif #ifndef PTR2nat # define PTR2nat(p) (PTRV)(p) #endif #ifndef NUM2PTR # define NUM2PTR(any,d) (any)PTR2nat(d) #endif #ifndef PTR2IV # define PTR2IV(p) INT2PTR(IV,p) #endif #ifndef PTR2UV # define PTR2UV(p) INT2PTR(UV,p) #endif #ifndef PTR2NV # define PTR2NV(p) NUM2PTR(NV,p) #endif #undef START_EXTERN_C #undef END_EXTERN_C #undef EXTERN_C #ifdef __cplusplus # define START_EXTERN_C extern "C" { # define END_EXTERN_C } # define EXTERN_C extern "C" #else # define START_EXTERN_C # define END_EXTERN_C # define EXTERN_C extern #endif #if defined(PERL_GCC_PEDANTIC) # ifndef PERL_GCC_BRACE_GROUPS_FORBIDDEN # define PERL_GCC_BRACE_GROUPS_FORBIDDEN # endif #endif #if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) && !defined(__cplusplus) # ifndef PERL_USE_GCC_BRACE_GROUPS # define PERL_USE_GCC_BRACE_GROUPS # endif #endif #undef STMT_START #undef STMT_END #ifdef PERL_USE_GCC_BRACE_GROUPS # define STMT_START (void)( /* gcc supports ``({ STATEMENTS; })'' */ # define STMT_END ) #else # if defined(VOIDFLAGS) && (VOIDFLAGS) && (defined(sun) || defined(__sun__)) && !defined(__GNUC__) # define STMT_START if (1) # define STMT_END else (void)0 # else # define STMT_START do # define STMT_END while (0) # endif #endif #ifndef boolSV # define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no) #endif /* DEFSV appears first in 5.004_56 */ #ifndef DEFSV # define DEFSV GvSV(PL_defgv) #endif #ifndef SAVE_DEFSV # define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv)) #endif #ifndef DEFSV_set # define DEFSV_set(sv) (DEFSV = (sv)) #endif /* Older perls (<=5.003) lack AvFILLp */ #ifndef AvFILLp # define AvFILLp AvFILL #endif #ifndef ERRSV # define ERRSV get_sv("@",FALSE) #endif /* Hint: gv_stashpvn * This function's backport doesn't support the length parameter, but * rather ignores it. Portability can only be ensured if the length * parameter is used for speed reasons, but the length can always be * correctly computed from the string argument. */ #ifndef gv_stashpvn # define gv_stashpvn(str,len,create) gv_stashpv(str,create) #endif /* Replace: 1 */ #ifndef get_cv # define get_cv perl_get_cv #endif #ifndef get_sv # define get_sv perl_get_sv #endif #ifndef get_av # define get_av perl_get_av #endif #ifndef get_hv # define get_hv perl_get_hv #endif /* Replace: 0 */ #ifndef dUNDERBAR # define dUNDERBAR dNOOP #endif #ifndef UNDERBAR # define UNDERBAR DEFSV #endif #ifndef dAX # define dAX I32 ax = MARK - PL_stack_base + 1 #endif #ifndef dITEMS # define dITEMS I32 items = SP - MARK #endif #ifndef dXSTARG # define dXSTARG SV * targ = sv_newmortal() #endif #ifndef dAXMARK # define dAXMARK I32 ax = POPMARK; \ register SV ** const mark = PL_stack_base + ax++ #endif #ifndef XSprePUSH # define XSprePUSH (sp = PL_stack_base + ax - 1) #endif #if (PERL_BCDVERSION < 0x5005000) # undef XSRETURN # define XSRETURN(off) \ STMT_START { \ PL_stack_sp = PL_stack_base + ax + ((off) - 1); \ return; \ } STMT_END #endif #ifndef XSPROTO # define XSPROTO(name) void name(pTHX_ CV* cv) #endif #ifndef SVfARG # define SVfARG(p) ((void*)(p)) #endif #ifndef PERL_ABS # define PERL_ABS(x) ((x) < 0 ? -(x) : (x)) #endif #ifndef dVAR # define dVAR dNOOP #endif #ifndef SVf # define SVf "_" #endif #ifndef UTF8_MAXBYTES # define UTF8_MAXBYTES UTF8_MAXLEN #endif #ifndef CPERLscope # define CPERLscope(x) x #endif #ifndef PERL_HASH # define PERL_HASH(hash,str,len) \ STMT_START { \ const char *s_PeRlHaSh = str; \ I32 i_PeRlHaSh = len; \ U32 hash_PeRlHaSh = 0; \ while (i_PeRlHaSh--) \ hash_PeRlHaSh = hash_PeRlHaSh * 33 + *s_PeRlHaSh++; \ (hash) = hash_PeRlHaSh; \ } STMT_END #endif #ifndef PERLIO_FUNCS_DECL # ifdef PERLIO_FUNCS_CONST # define PERLIO_FUNCS_DECL(funcs) const PerlIO_funcs funcs # define PERLIO_FUNCS_CAST(funcs) (PerlIO_funcs*)(funcs) # else # define PERLIO_FUNCS_DECL(funcs) PerlIO_funcs funcs # define PERLIO_FUNCS_CAST(funcs) (funcs) # endif #endif /* provide these typedefs for older perls */ #if (PERL_BCDVERSION < 0x5009003) # ifdef ARGSproto typedef OP* (CPERLscope(*Perl_ppaddr_t))(ARGSproto); # else typedef OP* (CPERLscope(*Perl_ppaddr_t))(pTHX); # endif typedef OP* (CPERLscope(*Perl_check_t)) (pTHX_ OP*); #endif #ifndef isPSXSPC # define isPSXSPC(c) (isSPACE(c) || (c) == '\v') #endif #ifndef isBLANK # define isBLANK(c) ((c) == ' ' || (c) == '\t') #endif #ifdef EBCDIC #ifndef isALNUMC # define isALNUMC(c) isalnum(c) #endif #ifndef isASCII # define isASCII(c) isascii(c) #endif #ifndef isCNTRL # define isCNTRL(c) iscntrl(c) #endif #ifndef isGRAPH # define isGRAPH(c) isgraph(c) #endif #ifndef isPRINT # define isPRINT(c) isprint(c) #endif #ifndef isPUNCT # define isPUNCT(c) ispunct(c) #endif #ifndef isXDIGIT # define isXDIGIT(c) isxdigit(c) #endif #else # if (PERL_BCDVERSION < 0x5010000) /* Hint: isPRINT * The implementation in older perl versions includes all of the * isSPACE() characters, which is wrong. The version provided by * Devel::PPPort always overrides a present buggy version. */ # undef isPRINT # endif #ifndef WIDEST_UTYPE # ifdef QUADKIND # ifdef U64TYPE # define WIDEST_UTYPE U64TYPE # else # define WIDEST_UTYPE Quad_t # endif # else # define WIDEST_UTYPE U32 # endif #endif #ifndef isALNUMC # define isALNUMC(c) (isALPHA(c) || isDIGIT(c)) #endif #ifndef isASCII # define isASCII(c) ((WIDEST_UTYPE) (c) <= 127) #endif #ifndef isCNTRL # define isCNTRL(c) ((WIDEST_UTYPE) (c) < ' ' || (c) == 127) #endif #ifndef isGRAPH # define isGRAPH(c) (isALNUM(c) || isPUNCT(c)) #endif #ifndef isPRINT # define isPRINT(c) (((c) >= 32 && (c) < 127)) #endif #ifndef isPUNCT # define isPUNCT(c) (((c) >= 33 && (c) <= 47) || ((c) >= 58 && (c) <= 64) || ((c) >= 91 && (c) <= 96) || ((c) >= 123 && (c) <= 126)) #endif #ifndef isXDIGIT # define isXDIGIT(c) (isDIGIT(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) #endif #endif /* Until we figure out how to support this in older perls... */ #if (PERL_BCDVERSION >= 0x5008000) #ifndef HeUTF8 # define HeUTF8(he) ((HeKLEN(he) == HEf_SVKEY) ? \ SvUTF8(HeKEY_sv(he)) : \ (U32)HeKUTF8(he)) #endif #endif #ifndef C_ARRAY_LENGTH # define C_ARRAY_LENGTH(a) (sizeof(a)/sizeof((a)[0])) #endif #ifndef C_ARRAY_END # define C_ARRAY_END(a) ((a) + C_ARRAY_LENGTH(a)) #endif #ifndef MUTABLE_PTR #if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) # define MUTABLE_PTR(p) ({ void *_p = (p); _p; }) #else # define MUTABLE_PTR(p) ((void *) (p)) #endif #endif #ifndef MUTABLE_SV # define MUTABLE_SV(p) ((SV *)MUTABLE_PTR(p)) #endif #ifdef NEED_mess_sv #define NEED_mess #endif #ifdef NEED_mess #define NEED_mess_nocontext #define NEED_vmess #endif #ifndef croak_sv #if (PERL_BCDVERSION >= 0x5007003) || ( (PERL_BCDVERSION >= 0x5006001) && (PERL_BCDVERSION < 0x5007000) ) # if ( (PERL_BCDVERSION >= 0x5008000) && (PERL_BCDVERSION < 0x5008009) ) || ( (PERL_BCDVERSION >= 0x5009000) && (PERL_BCDVERSION < 0x5010001) ) # define D_PPP_FIX_UTF8_ERRSV(errsv, sv) \ STMT_START { \ if (sv != ERRSV) \ SvFLAGS(ERRSV) = (SvFLAGS(ERRSV) & ~SVf_UTF8) | \ (SvFLAGS(sv) & SVf_UTF8); \ } STMT_END # else # define D_PPP_FIX_UTF8_ERRSV(errsv, sv) STMT_START {} STMT_END # endif # define croak_sv(sv) \ STMT_START { \ if (SvROK(sv)) { \ sv_setsv(ERRSV, sv); \ croak(NULL); \ } else { \ D_PPP_FIX_UTF8_ERRSV(ERRSV, sv); \ croak("%" SVf, SVfARG(sv)); \ } \ } STMT_END #elif (PERL_BCDVERSION >= 0x5004000) # define croak_sv(sv) croak("%" SVf, SVfARG(sv)) #else # define croak_sv(sv) croak("%s", SvPV_nolen(sv)) #endif #endif #ifndef die_sv #if defined(NEED_die_sv) static OP * DPPP_(my_die_sv)(pTHX_ SV *sv); static #else extern OP * DPPP_(my_die_sv)(pTHX_ SV *sv); #endif #if defined(NEED_die_sv) || defined(NEED_die_sv_GLOBAL) #ifdef die_sv # undef die_sv #endif #define die_sv(a) DPPP_(my_die_sv)(aTHX_ a) #define Perl_die_sv DPPP_(my_die_sv) OP * DPPP_(my_die_sv)(pTHX_ SV *sv) { croak_sv(sv); return (OP *)NULL; } #endif #endif #ifndef warn_sv #if (PERL_BCDVERSION >= 0x5004000) # define warn_sv(sv) warn("%" SVf, SVfARG(sv)) #else # define warn_sv(sv) warn("%s", SvPV_nolen(sv)) #endif #endif #ifndef vmess #if defined(NEED_vmess) static SV * DPPP_(my_vmess)(pTHX_ const char * pat, va_list * args); static #else extern SV * DPPP_(my_vmess)(pTHX_ const char * pat, va_list * args); #endif #if defined(NEED_vmess) || defined(NEED_vmess_GLOBAL) #ifdef vmess # undef vmess #endif #define vmess(a,b) DPPP_(my_vmess)(aTHX_ a,b) #define Perl_vmess DPPP_(my_vmess) SV* DPPP_(my_vmess)(pTHX_ const char* pat, va_list* args) { mess(pat, args); return PL_mess_sv; } #endif #endif #if (PERL_BCDVERSION < 0x5006000) #undef mess #endif #if !defined(mess_nocontext) && !defined(Perl_mess_nocontext) #if defined(NEED_mess_nocontext) static SV * DPPP_(my_mess_nocontext)(const char * pat, ...); static #else extern SV * DPPP_(my_mess_nocontext)(const char * pat, ...); #endif #if defined(NEED_mess_nocontext) || defined(NEED_mess_nocontext_GLOBAL) #define mess_nocontext DPPP_(my_mess_nocontext) #define Perl_mess_nocontext DPPP_(my_mess_nocontext) SV* DPPP_(my_mess_nocontext)(const char* pat, ...) { dTHX; SV *sv; va_list args; va_start(args, pat); sv = vmess(pat, &args); va_end(args); return sv; } #endif #endif #ifndef mess #if defined(NEED_mess) static SV * DPPP_(my_mess)(pTHX_ const char * pat, ...); static #else extern SV * DPPP_(my_mess)(pTHX_ const char * pat, ...); #endif #if defined(NEED_mess) || defined(NEED_mess_GLOBAL) #define Perl_mess DPPP_(my_mess) SV* DPPP_(my_mess)(pTHX_ const char* pat, ...) { SV *sv; va_list args; va_start(args, pat); sv = vmess(pat, &args); va_end(args); return sv; } #ifdef mess_nocontext #define mess mess_nocontext #else #define mess Perl_mess_nocontext #endif #endif #endif #ifndef mess_sv #if defined(NEED_mess_sv) static SV * DPPP_(my_mess_sv)(pTHX_ SV * basemsg, bool consume); static #else extern SV * DPPP_(my_mess_sv)(pTHX_ SV * basemsg, bool consume); #endif #if defined(NEED_mess_sv) || defined(NEED_mess_sv_GLOBAL) #ifdef mess_sv # undef mess_sv #endif #define mess_sv(a,b) DPPP_(my_mess_sv)(aTHX_ a,b) #define Perl_mess_sv DPPP_(my_mess_sv) SV * DPPP_(my_mess_sv)(pTHX_ SV *basemsg, bool consume) { SV *tmp; SV *ret; if (SvPOK(basemsg) && SvCUR(basemsg) && *(SvEND(basemsg)-1) == '\n') { if (consume) return basemsg; ret = mess(""); SvSetSV_nosteal(ret, basemsg); return ret; } if (consume) { sv_catsv(basemsg, mess("")); return basemsg; } ret = mess(""); tmp = newSVsv(ret); SvSetSV_nosteal(ret, basemsg); sv_catsv(ret, tmp); sv_dec(tmp); return ret; } #endif #endif #ifndef warn_nocontext #define warn_nocontext warn #endif #ifndef croak_nocontext #define croak_nocontext croak #endif #ifndef croak_no_modify #define croak_no_modify() croak_nocontext("%s", PL_no_modify) #define Perl_croak_no_modify() croak_no_modify() #endif #ifndef croak_memory_wrap #if (PERL_BCDVERSION >= 0x5009002) || ( (PERL_BCDVERSION >= 0x5008006) && (PERL_BCDVERSION < 0x5009000) ) # define croak_memory_wrap() croak_nocontext("%s", PL_memory_wrap) #else # define croak_memory_wrap() croak_nocontext("panic: memory wrap") #endif #endif #ifndef croak_xs_usage #if defined(NEED_croak_xs_usage) static void DPPP_(my_croak_xs_usage)(const CV * const cv, const char * const params); static #else extern void DPPP_(my_croak_xs_usage)(const CV * const cv, const char * const params); #endif #if defined(NEED_croak_xs_usage) || defined(NEED_croak_xs_usage_GLOBAL) #define croak_xs_usage DPPP_(my_croak_xs_usage) #define Perl_croak_xs_usage DPPP_(my_croak_xs_usage) #ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE #define PERL_ARGS_ASSERT_CROAK_XS_USAGE assert(cv); assert(params) #endif void DPPP_(my_croak_xs_usage)(const CV *const cv, const char *const params) { dTHX; const GV *const gv = CvGV(cv); PERL_ARGS_ASSERT_CROAK_XS_USAGE; if (gv) { const char *const gvname = GvNAME(gv); const HV *const stash = GvSTASH(gv); const char *const hvname = stash ? HvNAME(stash) : NULL; if (hvname) croak("Usage: %s::%s(%s)", hvname, gvname, params); else croak("Usage: %s(%s)", gvname, params); } else { /* Pants. I don't think that it should be possible to get here. */ croak("Usage: CODE(0x%" UVxf ")(%s)", PTR2UV(cv), params); } } #endif #endif #ifndef PERL_SIGNALS_UNSAFE_FLAG #define PERL_SIGNALS_UNSAFE_FLAG 0x0001 #if (PERL_BCDVERSION < 0x5008000) # define D_PPP_PERL_SIGNALS_INIT PERL_SIGNALS_UNSAFE_FLAG #else # define D_PPP_PERL_SIGNALS_INIT 0 #endif #if defined(NEED_PL_signals) static U32 DPPP_(my_PL_signals) = D_PPP_PERL_SIGNALS_INIT; #elif defined(NEED_PL_signals_GLOBAL) U32 DPPP_(my_PL_signals) = D_PPP_PERL_SIGNALS_INIT; #else extern U32 DPPP_(my_PL_signals); #endif #define PL_signals DPPP_(my_PL_signals) #endif /* Hint: PL_ppaddr * Calling an op via PL_ppaddr requires passing a context argument * for threaded builds. Since the context argument is different for * 5.005 perls, you can use aTHXR (supplied by c/ppport.h), which will * automatically be defined as the correct argument. */ #if (PERL_BCDVERSION <= 0x5005005) /* Replace: 1 */ # define PL_ppaddr ppaddr # define PL_no_modify no_modify /* Replace: 0 */ #endif #if (PERL_BCDVERSION <= 0x5004005) /* Replace: 1 */ # define PL_DBsignal DBsignal # define PL_DBsingle DBsingle # define PL_DBsub DBsub # define PL_DBtrace DBtrace # define PL_Sv Sv # define PL_bufend bufend # define PL_bufptr bufptr # define PL_compiling compiling # define PL_copline copline # define PL_curcop curcop # define PL_curstash curstash # define PL_debstash debstash # define PL_defgv defgv # define PL_diehook diehook # define PL_dirty dirty # define PL_dowarn dowarn # define PL_errgv errgv # define PL_error_count error_count # define PL_expect expect # define PL_hexdigit hexdigit # define PL_hints hints # define PL_in_my in_my # define PL_laststatval laststatval # define PL_lex_state lex_state # define PL_lex_stuff lex_stuff # define PL_linestr linestr # define PL_na na # define PL_perl_destruct_level perl_destruct_level # define PL_perldb perldb # define PL_rsfp_filters rsfp_filters # define PL_rsfp rsfp # define PL_stack_base stack_base # define PL_stack_sp stack_sp # define PL_statcache statcache # define PL_stdingv stdingv # define PL_sv_arenaroot sv_arenaroot # define PL_sv_no sv_no # define PL_sv_undef sv_undef # define PL_sv_yes sv_yes # define PL_tainted tainted # define PL_tainting tainting # define PL_tokenbuf tokenbuf /* Replace: 0 */ #endif /* Warning: PL_parser * For perl versions earlier than 5.9.5, this is an always * non-NULL dummy. Also, it cannot be dereferenced. Don't * use it if you can avoid is and unless you absolutely know * what you're doing. * If you always check that PL_parser is non-NULL, you can * define DPPP_PL_parser_NO_DUMMY to avoid the creation of * a dummy parser structure. */ #if (PERL_BCDVERSION >= 0x5009005) # ifdef DPPP_PL_parser_NO_DUMMY # define D_PPP_my_PL_parser_var(var) ((PL_parser ? PL_parser : \ (croak("panic: PL_parser == NULL in %s:%d", \ __FILE__, __LINE__), (yy_parser *) NULL))->var) # else # ifdef DPPP_PL_parser_NO_DUMMY_WARNING # define D_PPP_parser_dummy_warning(var) # else # define D_PPP_parser_dummy_warning(var) \ warn("warning: dummy PL_" #var " used in %s:%d", __FILE__, __LINE__), # endif # define D_PPP_my_PL_parser_var(var) ((PL_parser ? PL_parser : \ (D_PPP_parser_dummy_warning(var) &DPPP_(dummy_PL_parser)))->var) #if defined(NEED_PL_parser) static yy_parser DPPP_(dummy_PL_parser); #elif defined(NEED_PL_parser_GLOBAL) yy_parser DPPP_(dummy_PL_parser); #else extern yy_parser DPPP_(dummy_PL_parser); #endif # endif /* PL_expect, PL_copline, PL_rsfp, PL_rsfp_filters, PL_linestr, PL_bufptr, PL_bufend, PL_lex_state, PL_lex_stuff, PL_tokenbuf depends on PL_parser */ /* Warning: PL_expect, PL_copline, PL_rsfp, PL_rsfp_filters, PL_linestr, PL_bufptr, PL_bufend, PL_lex_state, PL_lex_stuff, PL_tokenbuf * Do not use this variable unless you know exactly what you're * doing. It is internal to the perl parser and may change or even * be removed in the future. As of perl 5.9.5, you have to check * for (PL_parser != NULL) for this variable to have any effect. * An always non-NULL PL_parser dummy is provided for earlier * perl versions. * If PL_parser is NULL when you try to access this variable, a * dummy is being accessed instead and a warning is issued unless * you define DPPP_PL_parser_NO_DUMMY_WARNING. * If DPPP_PL_parser_NO_DUMMY is defined, the code trying to access * this variable will croak with a panic message. */ # define PL_expect D_PPP_my_PL_parser_var(expect) # define PL_copline D_PPP_my_PL_parser_var(copline) # define PL_rsfp D_PPP_my_PL_parser_var(rsfp) # define PL_rsfp_filters D_PPP_my_PL_parser_var(rsfp_filters) # define PL_linestr D_PPP_my_PL_parser_var(linestr) # define PL_bufptr D_PPP_my_PL_parser_var(bufptr) # define PL_bufend D_PPP_my_PL_parser_var(bufend) # define PL_lex_state D_PPP_my_PL_parser_var(lex_state) # define PL_lex_stuff D_PPP_my_PL_parser_var(lex_stuff) # define PL_tokenbuf D_PPP_my_PL_parser_var(tokenbuf) # define PL_in_my D_PPP_my_PL_parser_var(in_my) # define PL_in_my_stash D_PPP_my_PL_parser_var(in_my_stash) # define PL_error_count D_PPP_my_PL_parser_var(error_count) #else /* ensure that PL_parser != NULL and cannot be dereferenced */ # define PL_parser ((void *) 1) #endif #ifndef mPUSHs # define mPUSHs(s) PUSHs(sv_2mortal(s)) #endif #ifndef PUSHmortal # define PUSHmortal PUSHs(sv_newmortal()) #endif #ifndef mPUSHp # define mPUSHp(p,l) sv_setpvn(PUSHmortal, (p), (l)) #endif #ifndef mPUSHn # define mPUSHn(n) sv_setnv(PUSHmortal, (NV)(n)) #endif #ifndef mPUSHi # define mPUSHi(i) sv_setiv(PUSHmortal, (IV)(i)) #endif #ifndef mPUSHu # define mPUSHu(u) sv_setuv(PUSHmortal, (UV)(u)) #endif #ifndef mXPUSHs # define mXPUSHs(s) XPUSHs(sv_2mortal(s)) #endif #ifndef XPUSHmortal # define XPUSHmortal XPUSHs(sv_newmortal()) #endif #ifndef mXPUSHp # define mXPUSHp(p,l) STMT_START { EXTEND(sp,1); sv_setpvn(PUSHmortal, (p), (l)); } STMT_END #endif #ifndef mXPUSHn # define mXPUSHn(n) STMT_START { EXTEND(sp,1); sv_setnv(PUSHmortal, (NV)(n)); } STMT_END #endif #ifndef mXPUSHi # define mXPUSHi(i) STMT_START { EXTEND(sp,1); sv_setiv(PUSHmortal, (IV)(i)); } STMT_END #endif #ifndef mXPUSHu # define mXPUSHu(u) STMT_START { EXTEND(sp,1); sv_setuv(PUSHmortal, (UV)(u)); } STMT_END #endif /* Replace: 1 */ #ifndef call_sv # define call_sv perl_call_sv #endif #ifndef call_pv # define call_pv perl_call_pv #endif #ifndef call_argv # define call_argv perl_call_argv #endif #ifndef call_method # define call_method perl_call_method #endif #ifndef eval_sv # define eval_sv perl_eval_sv #endif /* Replace: 0 */ #ifndef PERL_LOADMOD_DENY # define PERL_LOADMOD_DENY 0x1 #endif #ifndef PERL_LOADMOD_NOIMPORT # define PERL_LOADMOD_NOIMPORT 0x2 #endif #ifndef PERL_LOADMOD_IMPORT_OPS # define PERL_LOADMOD_IMPORT_OPS 0x4 #endif #ifndef G_METHOD # define G_METHOD 64 # ifdef call_sv # undef call_sv # endif # if (PERL_BCDVERSION < 0x5006000) # define call_sv(sv, flags) ((flags) & G_METHOD ? perl_call_method((char *) SvPV_nolen_const(sv), \ (flags) & ~G_METHOD) : perl_call_sv(sv, flags)) # else # define call_sv(sv, flags) ((flags) & G_METHOD ? Perl_call_method(aTHX_ (char *) SvPV_nolen_const(sv), \ (flags) & ~G_METHOD) : Perl_call_sv(aTHX_ sv, flags)) # endif #endif /* Replace perl_eval_pv with eval_pv */ #ifndef eval_pv #if defined(NEED_eval_pv) static SV* DPPP_(my_eval_pv)(char *p, I32 croak_on_error); static #else extern SV* DPPP_(my_eval_pv)(char *p, I32 croak_on_error); #endif #if defined(NEED_eval_pv) || defined(NEED_eval_pv_GLOBAL) #ifdef eval_pv # undef eval_pv #endif #define eval_pv(a,b) DPPP_(my_eval_pv)(aTHX_ a,b) #define Perl_eval_pv DPPP_(my_eval_pv) SV* DPPP_(my_eval_pv)(char *p, I32 croak_on_error) { dSP; SV* sv = newSVpv(p, 0); PUSHMARK(sp); eval_sv(sv, G_SCALAR); SvREFCNT_dec(sv); SPAGAIN; sv = POPs; PUTBACK; if (croak_on_error && SvTRUEx(ERRSV)) croak_sv(ERRSV); return sv; } #endif #endif #ifndef vload_module #if defined(NEED_vload_module) static void DPPP_(my_vload_module)(U32 flags, SV *name, SV *ver, va_list *args); static #else extern void DPPP_(my_vload_module)(U32 flags, SV *name, SV *ver, va_list *args); #endif #if defined(NEED_vload_module) || defined(NEED_vload_module_GLOBAL) #ifdef vload_module # undef vload_module #endif #define vload_module(a,b,c,d) DPPP_(my_vload_module)(aTHX_ a,b,c,d) #define Perl_vload_module DPPP_(my_vload_module) void DPPP_(my_vload_module)(U32 flags, SV *name, SV *ver, va_list *args) { dTHR; dVAR; OP *veop, *imop; OP * const modname = newSVOP(OP_CONST, 0, name); /* 5.005 has a somewhat hacky force_normal that doesn't croak on SvREADONLY() if PL_compling is true. Current perls take care in ck_require() to correctly turn off SvREADONLY before calling force_normal_flags(). This seems a better fix than fudging PL_compling */ SvREADONLY_off(((SVOP*)modname)->op_sv); modname->op_private |= OPpCONST_BARE; if (ver) { veop = newSVOP(OP_CONST, 0, ver); } else veop = NULL; if (flags & PERL_LOADMOD_NOIMPORT) { imop = sawparens(newNULLLIST()); } else if (flags & PERL_LOADMOD_IMPORT_OPS) { imop = va_arg(*args, OP*); } else { SV *sv; imop = NULL; sv = va_arg(*args, SV*); while (sv) { imop = append_elem(OP_LIST, imop, newSVOP(OP_CONST, 0, sv)); sv = va_arg(*args, SV*); } } { const line_t ocopline = PL_copline; COP * const ocurcop = PL_curcop; const int oexpect = PL_expect; #if (PERL_BCDVERSION >= 0x5004000) utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(FALSE, 0), veop, modname, imop); #elif (PERL_BCDVERSION > 0x5003000) utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(), veop, modname, imop); #else utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(), modname, imop); #endif PL_expect = oexpect; PL_copline = ocopline; PL_curcop = ocurcop; } } #endif #endif #ifndef load_module #if defined(NEED_load_module) static void DPPP_(my_load_module)(U32 flags, SV *name, SV *ver, ...); static #else extern void DPPP_(my_load_module)(U32 flags, SV *name, SV *ver, ...); #endif #if defined(NEED_load_module) || defined(NEED_load_module_GLOBAL) #ifdef load_module # undef load_module #endif #define load_module DPPP_(my_load_module) #define Perl_load_module DPPP_(my_load_module) void DPPP_(my_load_module)(U32 flags, SV *name, SV *ver, ...) { va_list args; va_start(args, ver); vload_module(flags, name, ver, &args); va_end(args); } #endif #endif #ifndef newRV_inc # define newRV_inc(sv) newRV(sv) /* Replace */ #endif #ifndef newRV_noinc #if defined(NEED_newRV_noinc) static SV * DPPP_(my_newRV_noinc)(SV *sv); static #else extern SV * DPPP_(my_newRV_noinc)(SV *sv); #endif #if defined(NEED_newRV_noinc) || defined(NEED_newRV_noinc_GLOBAL) #ifdef newRV_noinc # undef newRV_noinc #endif #define newRV_noinc(a) DPPP_(my_newRV_noinc)(aTHX_ a) #define Perl_newRV_noinc DPPP_(my_newRV_noinc) SV * DPPP_(my_newRV_noinc)(SV *sv) { SV *rv = (SV *)newRV(sv); SvREFCNT_dec(sv); return rv; } #endif #endif /* Hint: newCONSTSUB * Returns a CV* as of perl-5.7.1. This return value is not supported * by Devel::PPPort. */ /* newCONSTSUB from IO.xs is in the core starting with 5.004_63 */ #if (PERL_BCDVERSION < 0x5004063) && (PERL_BCDVERSION != 0x5004005) #if defined(NEED_newCONSTSUB) static void DPPP_(my_newCONSTSUB)(HV *stash, const char *name, SV *sv); static #else extern void DPPP_(my_newCONSTSUB)(HV *stash, const char *name, SV *sv); #endif #if defined(NEED_newCONSTSUB) || defined(NEED_newCONSTSUB_GLOBAL) #ifdef newCONSTSUB # undef newCONSTSUB #endif #define newCONSTSUB(a,b,c) DPPP_(my_newCONSTSUB)(aTHX_ a,b,c) #define Perl_newCONSTSUB DPPP_(my_newCONSTSUB) /* This is just a trick to avoid a dependency of newCONSTSUB on PL_parser */ /* (There's no PL_parser in perl < 5.005, so this is completely safe) */ #define D_PPP_PL_copline PL_copline void DPPP_(my_newCONSTSUB)(HV *stash, const char *name, SV *sv) { U32 oldhints = PL_hints; HV *old_cop_stash = PL_curcop->cop_stash; HV *old_curstash = PL_curstash; line_t oldline = PL_curcop->cop_line; PL_curcop->cop_line = D_PPP_PL_copline; PL_hints &= ~HINT_BLOCK_SCOPE; if (stash) PL_curstash = PL_curcop->cop_stash = stash; newSUB( #if (PERL_BCDVERSION < 0x5003022) start_subparse(), #elif (PERL_BCDVERSION == 0x5003022) start_subparse(0), #else /* 5.003_23 onwards */ start_subparse(FALSE, 0), #endif newSVOP(OP_CONST, 0, newSVpv((char *) name, 0)), newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */ newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv)) ); PL_hints = oldhints; PL_curcop->cop_stash = old_cop_stash; PL_curstash = old_curstash; PL_curcop->cop_line = oldline; } #endif #endif /* * Boilerplate macros for initializing and accessing interpreter-local * data from C. All statics in extensions should be reworked to use * this, if you want to make the extension thread-safe. See ext/re/re.xs * for an example of the use of these macros. * * Code that uses these macros is responsible for the following: * 1. #define MY_CXT_KEY to a unique string, e.g. "DynaLoader_guts" * 2. Declare a typedef named my_cxt_t that is a structure that contains * all the data that needs to be interpreter-local. * 3. Use the START_MY_CXT macro after the declaration of my_cxt_t. * 4. Use the MY_CXT_INIT macro such that it is called exactly once * (typically put in the BOOT: section). * 5. Use the members of the my_cxt_t structure everywhere as * MY_CXT.member. * 6. Use the dMY_CXT macro (a declaration) in all the functions that * access MY_CXT. */ #if defined(MULTIPLICITY) || defined(PERL_OBJECT) || \ defined(PERL_CAPI) || defined(PERL_IMPLICIT_CONTEXT) #ifndef START_MY_CXT /* This must appear in all extensions that define a my_cxt_t structure, * right after the definition (i.e. at file scope). The non-threads * case below uses it to declare the data as static. */ #define START_MY_CXT #if (PERL_BCDVERSION < 0x5004068) /* Fetches the SV that keeps the per-interpreter data. */ #define dMY_CXT_SV \ SV *my_cxt_sv = get_sv(MY_CXT_KEY, FALSE) #else /* >= perl5.004_68 */ #define dMY_CXT_SV \ SV *my_cxt_sv = *hv_fetch(PL_modglobal, MY_CXT_KEY, \ sizeof(MY_CXT_KEY)-1, TRUE) #endif /* < perl5.004_68 */ /* This declaration should be used within all functions that use the * interpreter-local data. */ #define dMY_CXT \ dMY_CXT_SV; \ my_cxt_t *my_cxtp = INT2PTR(my_cxt_t*,SvUV(my_cxt_sv)) /* Creates and zeroes the per-interpreter data. * (We allocate my_cxtp in a Perl SV so that it will be released when * the interpreter goes away.) */ #define MY_CXT_INIT \ dMY_CXT_SV; \ /* newSV() allocates one more than needed */ \ my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\ Zero(my_cxtp, 1, my_cxt_t); \ sv_setuv(my_cxt_sv, PTR2UV(my_cxtp)) /* This macro must be used to access members of the my_cxt_t structure. * e.g. MYCXT.some_data */ #define MY_CXT (*my_cxtp) /* Judicious use of these macros can reduce the number of times dMY_CXT * is used. Use is similar to pTHX, aTHX etc. */ #define pMY_CXT my_cxt_t *my_cxtp #define pMY_CXT_ pMY_CXT, #define _pMY_CXT ,pMY_CXT #define aMY_CXT my_cxtp #define aMY_CXT_ aMY_CXT, #define _aMY_CXT ,aMY_CXT #endif /* START_MY_CXT */ #ifndef MY_CXT_CLONE /* Clones the per-interpreter data. */ #define MY_CXT_CLONE \ dMY_CXT_SV; \ my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\ Copy(INT2PTR(my_cxt_t*, SvUV(my_cxt_sv)), my_cxtp, 1, my_cxt_t);\ sv_setuv(my_cxt_sv, PTR2UV(my_cxtp)) #endif #else /* single interpreter */ #ifndef START_MY_CXT #define START_MY_CXT static my_cxt_t my_cxt; #define dMY_CXT_SV dNOOP #define dMY_CXT dNOOP #define MY_CXT_INIT NOOP #define MY_CXT my_cxt #define pMY_CXT void #define pMY_CXT_ #define _pMY_CXT #define aMY_CXT #define aMY_CXT_ #define _aMY_CXT #endif /* START_MY_CXT */ #ifndef MY_CXT_CLONE #define MY_CXT_CLONE NOOP #endif #endif #ifndef IVdf # if IVSIZE == LONGSIZE # define IVdf "ld" # define UVuf "lu" # define UVof "lo" # define UVxf "lx" # define UVXf "lX" # elif IVSIZE == INTSIZE # define IVdf "d" # define UVuf "u" # define UVof "o" # define UVxf "x" # define UVXf "X" # else # error "cannot define IV/UV formats" # endif #endif #ifndef NVef # if defined(USE_LONG_DOUBLE) && defined(HAS_LONG_DOUBLE) && \ defined(PERL_PRIfldbl) && (PERL_BCDVERSION != 0x5006000) /* Not very likely, but let's try anyway. */ # define NVef PERL_PRIeldbl # define NVff PERL_PRIfldbl # define NVgf PERL_PRIgldbl # else # define NVef "e" # define NVff "f" # define NVgf "g" # endif #endif #ifndef SvREFCNT_inc # ifdef PERL_USE_GCC_BRACE_GROUPS # define SvREFCNT_inc(sv) \ ({ \ SV * const _sv = (SV*)(sv); \ if (_sv) \ (SvREFCNT(_sv))++; \ _sv; \ }) # else # define SvREFCNT_inc(sv) \ ((PL_Sv=(SV*)(sv)) ? (++(SvREFCNT(PL_Sv)),PL_Sv) : NULL) # endif #endif #ifndef SvREFCNT_inc_simple # ifdef PERL_USE_GCC_BRACE_GROUPS # define SvREFCNT_inc_simple(sv) \ ({ \ if (sv) \ (SvREFCNT(sv))++; \ (SV *)(sv); \ }) # else # define SvREFCNT_inc_simple(sv) \ ((sv) ? (SvREFCNT(sv)++,(SV*)(sv)) : NULL) # endif #endif #ifndef SvREFCNT_inc_NN # ifdef PERL_USE_GCC_BRACE_GROUPS # define SvREFCNT_inc_NN(sv) \ ({ \ SV * const _sv = (SV*)(sv); \ SvREFCNT(_sv)++; \ _sv; \ }) # else # define SvREFCNT_inc_NN(sv) \ (PL_Sv=(SV*)(sv),++(SvREFCNT(PL_Sv)),PL_Sv) # endif #endif #ifndef SvREFCNT_inc_void # ifdef PERL_USE_GCC_BRACE_GROUPS # define SvREFCNT_inc_void(sv) \ ({ \ SV * const _sv = (SV*)(sv); \ if (_sv) \ (void)(SvREFCNT(_sv)++); \ }) # else # define SvREFCNT_inc_void(sv) \ (void)((PL_Sv=(SV*)(sv)) ? ++(SvREFCNT(PL_Sv)) : 0) # endif #endif #ifndef SvREFCNT_inc_simple_void # define SvREFCNT_inc_simple_void(sv) STMT_START { if (sv) SvREFCNT(sv)++; } STMT_END #endif #ifndef SvREFCNT_inc_simple_NN # define SvREFCNT_inc_simple_NN(sv) (++SvREFCNT(sv), (SV*)(sv)) #endif #ifndef SvREFCNT_inc_void_NN # define SvREFCNT_inc_void_NN(sv) (void)(++SvREFCNT((SV*)(sv))) #endif #ifndef SvREFCNT_inc_simple_void_NN # define SvREFCNT_inc_simple_void_NN(sv) (void)(++SvREFCNT((SV*)(sv))) #endif #ifndef newSV_type #if defined(NEED_newSV_type) static SV* DPPP_(my_newSV_type)(pTHX_ svtype const t); static #else extern SV* DPPP_(my_newSV_type)(pTHX_ svtype const t); #endif #if defined(NEED_newSV_type) || defined(NEED_newSV_type_GLOBAL) #ifdef newSV_type # undef newSV_type #endif #define newSV_type(a) DPPP_(my_newSV_type)(aTHX_ a) #define Perl_newSV_type DPPP_(my_newSV_type) SV* DPPP_(my_newSV_type)(pTHX_ svtype const t) { SV* const sv = newSV(0); sv_upgrade(sv, t); return sv; } #endif #endif #if (PERL_BCDVERSION < 0x5006000) # define D_PPP_CONSTPV_ARG(x) ((char *) (x)) #else # define D_PPP_CONSTPV_ARG(x) (x) #endif #ifndef newSVpvn # define newSVpvn(data,len) ((data) \ ? ((len) ? newSVpv((data), (len)) : newSVpv("", 0)) \ : newSV(0)) #endif #ifndef newSVpvn_utf8 # define newSVpvn_utf8(s, len, u) newSVpvn_flags((s), (len), (u) ? SVf_UTF8 : 0) #endif #ifndef SVf_UTF8 # define SVf_UTF8 0 #endif #ifndef newSVpvn_flags #if defined(NEED_newSVpvn_flags) static SV * DPPP_(my_newSVpvn_flags)(pTHX_ const char *s, STRLEN len, U32 flags); static #else extern SV * DPPP_(my_newSVpvn_flags)(pTHX_ const char *s, STRLEN len, U32 flags); #endif #if defined(NEED_newSVpvn_flags) || defined(NEED_newSVpvn_flags_GLOBAL) #ifdef newSVpvn_flags # undef newSVpvn_flags #endif #define newSVpvn_flags(a,b,c) DPPP_(my_newSVpvn_flags)(aTHX_ a,b,c) #define Perl_newSVpvn_flags DPPP_(my_newSVpvn_flags) SV * DPPP_(my_newSVpvn_flags)(pTHX_ const char *s, STRLEN len, U32 flags) { SV *sv = newSVpvn(D_PPP_CONSTPV_ARG(s), len); SvFLAGS(sv) |= (flags & SVf_UTF8); return (flags & SVs_TEMP) ? sv_2mortal(sv) : sv; } #endif #endif /* Backwards compatibility stuff... :-( */ #if !defined(NEED_sv_2pv_flags) && defined(NEED_sv_2pv_nolen) # define NEED_sv_2pv_flags #endif #if !defined(NEED_sv_2pv_flags_GLOBAL) && defined(NEED_sv_2pv_nolen_GLOBAL) # define NEED_sv_2pv_flags_GLOBAL #endif /* Hint: sv_2pv_nolen * Use the SvPV_nolen() or SvPV_nolen_const() macros instead of sv_2pv_nolen(). */ #ifndef sv_2pv_nolen # define sv_2pv_nolen(sv) SvPV_nolen(sv) #endif #ifdef SvPVbyte /* Hint: SvPVbyte * Does not work in perl-5.6.1, c/ppport.h implements a version * borrowed from perl-5.7.3. */ #if (PERL_BCDVERSION < 0x5007000) #if defined(NEED_sv_2pvbyte) static char * DPPP_(my_sv_2pvbyte)(pTHX_ SV *sv, STRLEN *lp); static #else extern char * DPPP_(my_sv_2pvbyte)(pTHX_ SV *sv, STRLEN *lp); #endif #if defined(NEED_sv_2pvbyte) || defined(NEED_sv_2pvbyte_GLOBAL) #ifdef sv_2pvbyte # undef sv_2pvbyte #endif #define sv_2pvbyte(a,b) DPPP_(my_sv_2pvbyte)(aTHX_ a,b) #define Perl_sv_2pvbyte DPPP_(my_sv_2pvbyte) char * DPPP_(my_sv_2pvbyte)(pTHX_ SV *sv, STRLEN *lp) { sv_utf8_downgrade(sv,0); return SvPV(sv,*lp); } #endif /* Hint: sv_2pvbyte * Use the SvPVbyte() macro instead of sv_2pvbyte(). */ #undef SvPVbyte #define SvPVbyte(sv, lp) \ ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp)) #endif #else # define SvPVbyte SvPV # define sv_2pvbyte sv_2pv #endif #ifndef sv_2pvbyte_nolen # define sv_2pvbyte_nolen(sv) sv_2pv_nolen(sv) #endif /* Hint: sv_pvn * Always use the SvPV() macro instead of sv_pvn(). */ /* Hint: sv_pvn_force * Always use the SvPV_force() macro instead of sv_pvn_force(). */ /* If these are undefined, they're not handled by the core anyway */ #ifndef SV_IMMEDIATE_UNREF # define SV_IMMEDIATE_UNREF 0 #endif #ifndef SV_GMAGIC # define SV_GMAGIC 0 #endif #ifndef SV_COW_DROP_PV # define SV_COW_DROP_PV 0 #endif #ifndef SV_UTF8_NO_ENCODING # define SV_UTF8_NO_ENCODING 0 #endif #ifndef SV_NOSTEAL # define SV_NOSTEAL 0 #endif #ifndef SV_CONST_RETURN # define SV_CONST_RETURN 0 #endif #ifndef SV_MUTABLE_RETURN # define SV_MUTABLE_RETURN 0 #endif #ifndef SV_SMAGIC # define SV_SMAGIC 0 #endif #ifndef SV_HAS_TRAILING_NUL # define SV_HAS_TRAILING_NUL 0 #endif #ifndef SV_COW_SHARED_HASH_KEYS # define SV_COW_SHARED_HASH_KEYS 0 #endif #if (PERL_BCDVERSION < 0x5007002) #if defined(NEED_sv_2pv_flags) static char * DPPP_(my_sv_2pv_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags); static #else extern char * DPPP_(my_sv_2pv_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags); #endif #if defined(NEED_sv_2pv_flags) || defined(NEED_sv_2pv_flags_GLOBAL) #ifdef sv_2pv_flags # undef sv_2pv_flags #endif #define sv_2pv_flags(a,b,c) DPPP_(my_sv_2pv_flags)(aTHX_ a,b,c) #define Perl_sv_2pv_flags DPPP_(my_sv_2pv_flags) char * DPPP_(my_sv_2pv_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags) { STRLEN n_a = (STRLEN) flags; return sv_2pv(sv, lp ? lp : &n_a); } #endif #if defined(NEED_sv_pvn_force_flags) static char * DPPP_(my_sv_pvn_force_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags); static #else extern char * DPPP_(my_sv_pvn_force_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags); #endif #if defined(NEED_sv_pvn_force_flags) || defined(NEED_sv_pvn_force_flags_GLOBAL) #ifdef sv_pvn_force_flags # undef sv_pvn_force_flags #endif #define sv_pvn_force_flags(a,b,c) DPPP_(my_sv_pvn_force_flags)(aTHX_ a,b,c) #define Perl_sv_pvn_force_flags DPPP_(my_sv_pvn_force_flags) char * DPPP_(my_sv_pvn_force_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags) { STRLEN n_a = (STRLEN) flags; return sv_pvn_force(sv, lp ? lp : &n_a); } #endif #endif #if (PERL_BCDVERSION < 0x5008008) || ( (PERL_BCDVERSION >= 0x5009000) && (PERL_BCDVERSION < 0x5009003) ) # define D_PPP_SVPV_NOLEN_LP_ARG &PL_na #else # define D_PPP_SVPV_NOLEN_LP_ARG 0 #endif #ifndef SvPV_const # define SvPV_const(sv, lp) SvPV_flags_const(sv, lp, SV_GMAGIC) #endif #ifndef SvPV_mutable # define SvPV_mutable(sv, lp) SvPV_flags_mutable(sv, lp, SV_GMAGIC) #endif #ifndef SvPV_flags # define SvPV_flags(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv_flags(sv, &lp, flags)) #endif #ifndef SvPV_flags_const # define SvPV_flags_const(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX_const(sv)) : \ (const char*) sv_2pv_flags(sv, &lp, flags|SV_CONST_RETURN)) #endif #ifndef SvPV_flags_const_nolen # define SvPV_flags_const_nolen(sv, flags) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? SvPVX_const(sv) : \ (const char*) sv_2pv_flags(sv, D_PPP_SVPV_NOLEN_LP_ARG, flags|SV_CONST_RETURN)) #endif #ifndef SvPV_flags_mutable # define SvPV_flags_mutable(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) : \ sv_2pv_flags(sv, &lp, flags|SV_MUTABLE_RETURN)) #endif #ifndef SvPV_force # define SvPV_force(sv, lp) SvPV_force_flags(sv, lp, SV_GMAGIC) #endif #ifndef SvPV_force_nolen # define SvPV_force_nolen(sv) SvPV_force_flags_nolen(sv, SV_GMAGIC) #endif #ifndef SvPV_force_mutable # define SvPV_force_mutable(sv, lp) SvPV_force_flags_mutable(sv, lp, SV_GMAGIC) #endif #ifndef SvPV_force_nomg # define SvPV_force_nomg(sv, lp) SvPV_force_flags(sv, lp, 0) #endif #ifndef SvPV_force_nomg_nolen # define SvPV_force_nomg_nolen(sv) SvPV_force_flags_nolen(sv, 0) #endif #ifndef SvPV_force_flags # define SvPV_force_flags(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force_flags(sv, &lp, flags)) #endif #ifndef SvPV_force_flags_nolen # define SvPV_force_flags_nolen(sv, flags) \ ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ ? SvPVX(sv) : sv_pvn_force_flags(sv, D_PPP_SVPV_NOLEN_LP_ARG, flags)) #endif #ifndef SvPV_force_flags_mutable # define SvPV_force_flags_mutable(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) \ : sv_pvn_force_flags(sv, &lp, flags|SV_MUTABLE_RETURN)) #endif #ifndef SvPV_nolen # define SvPV_nolen(sv) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? SvPVX(sv) : sv_2pv_flags(sv, D_PPP_SVPV_NOLEN_LP_ARG, SV_GMAGIC)) #endif #ifndef SvPV_nolen_const # define SvPV_nolen_const(sv) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? SvPVX_const(sv) : sv_2pv_flags(sv, D_PPP_SVPV_NOLEN_LP_ARG, SV_GMAGIC|SV_CONST_RETURN)) #endif #ifndef SvPV_nomg # define SvPV_nomg(sv, lp) SvPV_flags(sv, lp, 0) #endif #ifndef SvPV_nomg_const # define SvPV_nomg_const(sv, lp) SvPV_flags_const(sv, lp, 0) #endif #ifndef SvPV_nomg_const_nolen # define SvPV_nomg_const_nolen(sv) SvPV_flags_const_nolen(sv, 0) #endif #ifndef SvPV_nomg_nolen # define SvPV_nomg_nolen(sv) ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? SvPVX(sv) : sv_2pv_flags(sv, D_PPP_SVPV_NOLEN_LP_ARG, 0)) #endif #ifndef SvPV_renew # define SvPV_renew(sv,n) STMT_START { SvLEN_set(sv, n); \ SvPV_set((sv), (char *) saferealloc( \ (Malloc_t)SvPVX(sv), (MEM_SIZE)((n)))); \ } STMT_END #endif #ifndef SvMAGIC_set # define SvMAGIC_set(sv, val) \ STMT_START { assert(SvTYPE(sv) >= SVt_PVMG); \ (((XPVMG*) SvANY(sv))->xmg_magic = (val)); } STMT_END #endif #if (PERL_BCDVERSION < 0x5009003) #ifndef SvPVX_const # define SvPVX_const(sv) ((const char*) (0 + SvPVX(sv))) #endif #ifndef SvPVX_mutable # define SvPVX_mutable(sv) (0 + SvPVX(sv)) #endif #ifndef SvRV_set # define SvRV_set(sv, val) \ STMT_START { assert(SvTYPE(sv) >= SVt_RV); \ (((XRV*) SvANY(sv))->xrv_rv = (val)); } STMT_END #endif #else #ifndef SvPVX_const # define SvPVX_const(sv) ((const char*)((sv)->sv_u.svu_pv)) #endif #ifndef SvPVX_mutable # define SvPVX_mutable(sv) ((sv)->sv_u.svu_pv) #endif #ifndef SvRV_set # define SvRV_set(sv, val) \ STMT_START { assert(SvTYPE(sv) >= SVt_RV); \ ((sv)->sv_u.svu_rv = (val)); } STMT_END #endif #endif #ifndef SvSTASH_set # define SvSTASH_set(sv, val) \ STMT_START { assert(SvTYPE(sv) >= SVt_PVMG); \ (((XPVMG*) SvANY(sv))->xmg_stash = (val)); } STMT_END #endif #if (PERL_BCDVERSION < 0x5004000) #ifndef SvUV_set # define SvUV_set(sv, val) \ STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \ (((XPVIV*) SvANY(sv))->xiv_iv = (IV) (val)); } STMT_END #endif #else #ifndef SvUV_set # define SvUV_set(sv, val) \ STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \ (((XPVUV*) SvANY(sv))->xuv_uv = (val)); } STMT_END #endif #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(vnewSVpvf) #if defined(NEED_vnewSVpvf) static SV * DPPP_(my_vnewSVpvf)(pTHX_ const char *pat, va_list *args); static #else extern SV * DPPP_(my_vnewSVpvf)(pTHX_ const char *pat, va_list *args); #endif #if defined(NEED_vnewSVpvf) || defined(NEED_vnewSVpvf_GLOBAL) #ifdef vnewSVpvf # undef vnewSVpvf #endif #define vnewSVpvf(a,b) DPPP_(my_vnewSVpvf)(aTHX_ a,b) #define Perl_vnewSVpvf DPPP_(my_vnewSVpvf) SV * DPPP_(my_vnewSVpvf)(pTHX_ const char *pat, va_list *args) { register SV *sv = newSV(0); sv_vsetpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)); return sv; } #endif #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_vcatpvf) # define sv_vcatpvf(sv, pat, args) sv_vcatpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)) #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_vsetpvf) # define sv_vsetpvf(sv, pat, args) sv_vsetpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)) #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_catpvf_mg) #if defined(NEED_sv_catpvf_mg) static void DPPP_(my_sv_catpvf_mg)(pTHX_ SV *sv, const char *pat, ...); static #else extern void DPPP_(my_sv_catpvf_mg)(pTHX_ SV *sv, const char *pat, ...); #endif #if defined(NEED_sv_catpvf_mg) || defined(NEED_sv_catpvf_mg_GLOBAL) #define Perl_sv_catpvf_mg DPPP_(my_sv_catpvf_mg) void DPPP_(my_sv_catpvf_mg)(pTHX_ SV *sv, const char *pat, ...) { va_list args; va_start(args, pat); sv_vcatpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*)); SvSETMAGIC(sv); va_end(args); } #endif #endif #ifdef PERL_IMPLICIT_CONTEXT #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_catpvf_mg_nocontext) #if defined(NEED_sv_catpvf_mg_nocontext) static void DPPP_(my_sv_catpvf_mg_nocontext)(SV *sv, const char *pat, ...); static #else extern void DPPP_(my_sv_catpvf_mg_nocontext)(SV *sv, const char *pat, ...); #endif #if defined(NEED_sv_catpvf_mg_nocontext) || defined(NEED_sv_catpvf_mg_nocontext_GLOBAL) #define sv_catpvf_mg_nocontext DPPP_(my_sv_catpvf_mg_nocontext) #define Perl_sv_catpvf_mg_nocontext DPPP_(my_sv_catpvf_mg_nocontext) void DPPP_(my_sv_catpvf_mg_nocontext)(SV *sv, const char *pat, ...) { dTHX; va_list args; va_start(args, pat); sv_vcatpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*)); SvSETMAGIC(sv); va_end(args); } #endif #endif #endif /* sv_catpvf_mg depends on sv_catpvf_mg_nocontext */ #ifndef sv_catpvf_mg # ifdef PERL_IMPLICIT_CONTEXT # define sv_catpvf_mg Perl_sv_catpvf_mg_nocontext # else # define sv_catpvf_mg Perl_sv_catpvf_mg # endif #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_vcatpvf_mg) # define sv_vcatpvf_mg(sv, pat, args) \ STMT_START { \ sv_vcatpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)); \ SvSETMAGIC(sv); \ } STMT_END #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_setpvf_mg) #if defined(NEED_sv_setpvf_mg) static void DPPP_(my_sv_setpvf_mg)(pTHX_ SV *sv, const char *pat, ...); static #else extern void DPPP_(my_sv_setpvf_mg)(pTHX_ SV *sv, const char *pat, ...); #endif #if defined(NEED_sv_setpvf_mg) || defined(NEED_sv_setpvf_mg_GLOBAL) #define Perl_sv_setpvf_mg DPPP_(my_sv_setpvf_mg) void DPPP_(my_sv_setpvf_mg)(pTHX_ SV *sv, const char *pat, ...) { va_list args; va_start(args, pat); sv_vsetpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*)); SvSETMAGIC(sv); va_end(args); } #endif #endif #ifdef PERL_IMPLICIT_CONTEXT #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_setpvf_mg_nocontext) #if defined(NEED_sv_setpvf_mg_nocontext) static void DPPP_(my_sv_setpvf_mg_nocontext)(SV *sv, const char *pat, ...); static #else extern void DPPP_(my_sv_setpvf_mg_nocontext)(SV *sv, const char *pat, ...); #endif #if defined(NEED_sv_setpvf_mg_nocontext) || defined(NEED_sv_setpvf_mg_nocontext_GLOBAL) #define sv_setpvf_mg_nocontext DPPP_(my_sv_setpvf_mg_nocontext) #define Perl_sv_setpvf_mg_nocontext DPPP_(my_sv_setpvf_mg_nocontext) void DPPP_(my_sv_setpvf_mg_nocontext)(SV *sv, const char *pat, ...) { dTHX; va_list args; va_start(args, pat); sv_vsetpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*)); SvSETMAGIC(sv); va_end(args); } #endif #endif #endif /* sv_setpvf_mg depends on sv_setpvf_mg_nocontext */ #ifndef sv_setpvf_mg # ifdef PERL_IMPLICIT_CONTEXT # define sv_setpvf_mg Perl_sv_setpvf_mg_nocontext # else # define sv_setpvf_mg Perl_sv_setpvf_mg # endif #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_vsetpvf_mg) # define sv_vsetpvf_mg(sv, pat, args) \ STMT_START { \ sv_vsetpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)); \ SvSETMAGIC(sv); \ } STMT_END #endif /* Hint: newSVpvn_share * The SVs created by this function only mimic the behaviour of * shared PVs without really being shared. Only use if you know * what you're doing. */ #ifndef newSVpvn_share #if defined(NEED_newSVpvn_share) static SV * DPPP_(my_newSVpvn_share)(pTHX_ const char *src, I32 len, U32 hash); static #else extern SV * DPPP_(my_newSVpvn_share)(pTHX_ const char *src, I32 len, U32 hash); #endif #if defined(NEED_newSVpvn_share) || defined(NEED_newSVpvn_share_GLOBAL) #ifdef newSVpvn_share # undef newSVpvn_share #endif #define newSVpvn_share(a,b,c) DPPP_(my_newSVpvn_share)(aTHX_ a,b,c) #define Perl_newSVpvn_share DPPP_(my_newSVpvn_share) SV * DPPP_(my_newSVpvn_share)(pTHX_ const char *src, I32 len, U32 hash) { SV *sv; if (len < 0) len = -len; if (!hash) PERL_HASH(hash, (char*) src, len); sv = newSVpvn((char *) src, len); sv_upgrade(sv, SVt_PVIV); SvIVX(sv) = hash; SvREADONLY_on(sv); SvPOK_on(sv); return sv; } #endif #endif #ifndef SvSHARED_HASH # define SvSHARED_HASH(sv) (0 + SvUVX(sv)) #endif #ifndef HvNAME_get # define HvNAME_get(hv) HvNAME(hv) #endif #ifndef HvNAMELEN_get # define HvNAMELEN_get(hv) (HvNAME_get(hv) ? (I32)strlen(HvNAME_get(hv)) : 0) #endif #ifndef gv_fetchpvn_flags #if defined(NEED_gv_fetchpvn_flags) static GV* DPPP_(my_gv_fetchpvn_flags)(pTHX_ const char* name, STRLEN len, int flags, int types); static #else extern GV* DPPP_(my_gv_fetchpvn_flags)(pTHX_ const char* name, STRLEN len, int flags, int types); #endif #if defined(NEED_gv_fetchpvn_flags) || defined(NEED_gv_fetchpvn_flags_GLOBAL) #ifdef gv_fetchpvn_flags # undef gv_fetchpvn_flags #endif #define gv_fetchpvn_flags(a,b,c,d) DPPP_(my_gv_fetchpvn_flags)(aTHX_ a,b,c,d) #define Perl_gv_fetchpvn_flags DPPP_(my_gv_fetchpvn_flags) GV* DPPP_(my_gv_fetchpvn_flags)(pTHX_ const char* name, STRLEN len, int flags, int types) { char *namepv = savepvn(name, len); GV* stash = gv_fetchpv(namepv, TRUE, SVt_PVHV); Safefree(namepv); return stash; } #endif #endif #ifndef GvSVn # define GvSVn(gv) GvSV(gv) #endif #ifndef isGV_with_GP # define isGV_with_GP(gv) isGV(gv) #endif #ifndef gv_fetchsv # define gv_fetchsv(name, flags, svt) gv_fetchpv(SvPV_nolen_const(name), flags, svt) #endif #ifndef get_cvn_flags # define get_cvn_flags(name, namelen, flags) get_cv(name, flags) #endif #ifndef gv_init_pvn # define gv_init_pvn(gv, stash, ptr, len, flags) gv_init(gv, stash, ptr, len, flags & GV_ADDMULTI ? TRUE : FALSE) #endif #ifndef WARN_ALL # define WARN_ALL 0 #endif #ifndef WARN_CLOSURE # define WARN_CLOSURE 1 #endif #ifndef WARN_DEPRECATED # define WARN_DEPRECATED 2 #endif #ifndef WARN_EXITING # define WARN_EXITING 3 #endif #ifndef WARN_GLOB # define WARN_GLOB 4 #endif #ifndef WARN_IO # define WARN_IO 5 #endif #ifndef WARN_CLOSED # define WARN_CLOSED 6 #endif #ifndef WARN_EXEC # define WARN_EXEC 7 #endif #ifndef WARN_LAYER # define WARN_LAYER 8 #endif #ifndef WARN_NEWLINE # define WARN_NEWLINE 9 #endif #ifndef WARN_PIPE # define WARN_PIPE 10 #endif #ifndef WARN_UNOPENED # define WARN_UNOPENED 11 #endif #ifndef WARN_MISC # define WARN_MISC 12 #endif #ifndef WARN_NUMERIC # define WARN_NUMERIC 13 #endif #ifndef WARN_ONCE # define WARN_ONCE 14 #endif #ifndef WARN_OVERFLOW # define WARN_OVERFLOW 15 #endif #ifndef WARN_PACK # define WARN_PACK 16 #endif #ifndef WARN_PORTABLE # define WARN_PORTABLE 17 #endif #ifndef WARN_RECURSION # define WARN_RECURSION 18 #endif #ifndef WARN_REDEFINE # define WARN_REDEFINE 19 #endif #ifndef WARN_REGEXP # define WARN_REGEXP 20 #endif #ifndef WARN_SEVERE # define WARN_SEVERE 21 #endif #ifndef WARN_DEBUGGING # define WARN_DEBUGGING 22 #endif #ifndef WARN_INPLACE # define WARN_INPLACE 23 #endif #ifndef WARN_INTERNAL # define WARN_INTERNAL 24 #endif #ifndef WARN_MALLOC # define WARN_MALLOC 25 #endif #ifndef WARN_SIGNAL # define WARN_SIGNAL 26 #endif #ifndef WARN_SUBSTR # define WARN_SUBSTR 27 #endif #ifndef WARN_SYNTAX # define WARN_SYNTAX 28 #endif #ifndef WARN_AMBIGUOUS # define WARN_AMBIGUOUS 29 #endif #ifndef WARN_BAREWORD # define WARN_BAREWORD 30 #endif #ifndef WARN_DIGIT # define WARN_DIGIT 31 #endif #ifndef WARN_PARENTHESIS # define WARN_PARENTHESIS 32 #endif #ifndef WARN_PRECEDENCE # define WARN_PRECEDENCE 33 #endif #ifndef WARN_PRINTF # define WARN_PRINTF 34 #endif #ifndef WARN_PROTOTYPE # define WARN_PROTOTYPE 35 #endif #ifndef WARN_QW # define WARN_QW 36 #endif #ifndef WARN_RESERVED # define WARN_RESERVED 37 #endif #ifndef WARN_SEMICOLON # define WARN_SEMICOLON 38 #endif #ifndef WARN_TAINT # define WARN_TAINT 39 #endif #ifndef WARN_THREADS # define WARN_THREADS 40 #endif #ifndef WARN_UNINITIALIZED # define WARN_UNINITIALIZED 41 #endif #ifndef WARN_UNPACK # define WARN_UNPACK 42 #endif #ifndef WARN_UNTIE # define WARN_UNTIE 43 #endif #ifndef WARN_UTF8 # define WARN_UTF8 44 #endif #ifndef WARN_VOID # define WARN_VOID 45 #endif #ifndef WARN_ASSERTIONS # define WARN_ASSERTIONS 46 #endif #ifndef packWARN # define packWARN(a) (a) #endif #ifndef ckWARN # ifdef G_WARN_ON # define ckWARN(a) (PL_dowarn & G_WARN_ON) # else # define ckWARN(a) PL_dowarn # endif #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(warner) #if defined(NEED_warner) static void DPPP_(my_warner)(U32 err, const char *pat, ...); static #else extern void DPPP_(my_warner)(U32 err, const char *pat, ...); #endif #if defined(NEED_warner) || defined(NEED_warner_GLOBAL) #define Perl_warner DPPP_(my_warner) void DPPP_(my_warner)(U32 err, const char *pat, ...) { SV *sv; va_list args; PERL_UNUSED_ARG(err); va_start(args, pat); sv = vnewSVpvf(pat, &args); va_end(args); sv_2mortal(sv); warn("%s", SvPV_nolen(sv)); } #define warner Perl_warner #define Perl_warner_nocontext Perl_warner #endif #endif /* concatenating with "" ensures that only literal strings are accepted as argument * note that STR_WITH_LEN() can't be used as argument to macros or functions that * under some configurations might be macros */ #ifndef STR_WITH_LEN # define STR_WITH_LEN(s) (s ""), (sizeof(s)-1) #endif #ifndef newSVpvs # define newSVpvs(str) newSVpvn(str "", sizeof(str) - 1) #endif #ifndef newSVpvs_flags # define newSVpvs_flags(str, flags) newSVpvn_flags(str "", sizeof(str) - 1, flags) #endif #ifndef newSVpvs_share # define newSVpvs_share(str) newSVpvn_share(str "", sizeof(str) - 1, 0) #endif #ifndef sv_catpvs # define sv_catpvs(sv, str) sv_catpvn(sv, str "", sizeof(str) - 1) #endif #ifndef sv_setpvs # define sv_setpvs(sv, str) sv_setpvn(sv, str "", sizeof(str) - 1) #endif #ifndef hv_fetchs # define hv_fetchs(hv, key, lval) hv_fetch(hv, key "", sizeof(key) - 1, lval) #endif #ifndef hv_stores # define hv_stores(hv, key, val) hv_store(hv, key "", sizeof(key) - 1, val, 0) #endif #ifndef gv_fetchpvs # define gv_fetchpvs(name, flags, svt) gv_fetchpvn_flags(name "", sizeof(name) - 1, flags, svt) #endif #ifndef gv_stashpvs # define gv_stashpvs(name, flags) gv_stashpvn(name "", sizeof(name) - 1, flags) #endif #ifndef get_cvs # define get_cvs(name, flags) get_cvn_flags(name "", sizeof(name)-1, flags) #endif #ifndef SvGETMAGIC # define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END #endif /* That's the best we can do... */ #ifndef sv_catpvn_nomg # define sv_catpvn_nomg sv_catpvn #endif #ifndef sv_catsv_nomg # define sv_catsv_nomg sv_catsv #endif #ifndef sv_setsv_nomg # define sv_setsv_nomg sv_setsv #endif #ifndef sv_pvn_nomg # define sv_pvn_nomg sv_pvn #endif #ifndef SvIV_nomg # define SvIV_nomg SvIV #endif #ifndef SvUV_nomg # define SvUV_nomg SvUV #endif #ifndef sv_catpv_mg # define sv_catpv_mg(sv, ptr) \ STMT_START { \ SV *TeMpSv = sv; \ sv_catpv(TeMpSv,ptr); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_catpvn_mg # define sv_catpvn_mg(sv, ptr, len) \ STMT_START { \ SV *TeMpSv = sv; \ sv_catpvn(TeMpSv,ptr,len); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_catsv_mg # define sv_catsv_mg(dsv, ssv) \ STMT_START { \ SV *TeMpSv = dsv; \ sv_catsv(TeMpSv,ssv); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setiv_mg # define sv_setiv_mg(sv, i) \ STMT_START { \ SV *TeMpSv = sv; \ sv_setiv(TeMpSv,i); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setnv_mg # define sv_setnv_mg(sv, num) \ STMT_START { \ SV *TeMpSv = sv; \ sv_setnv(TeMpSv,num); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setpv_mg # define sv_setpv_mg(sv, ptr) \ STMT_START { \ SV *TeMpSv = sv; \ sv_setpv(TeMpSv,ptr); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setpvn_mg # define sv_setpvn_mg(sv, ptr, len) \ STMT_START { \ SV *TeMpSv = sv; \ sv_setpvn(TeMpSv,ptr,len); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setsv_mg # define sv_setsv_mg(dsv, ssv) \ STMT_START { \ SV *TeMpSv = dsv; \ sv_setsv(TeMpSv,ssv); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setuv_mg # define sv_setuv_mg(sv, i) \ STMT_START { \ SV *TeMpSv = sv; \ sv_setuv(TeMpSv,i); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_usepvn_mg # define sv_usepvn_mg(sv, ptr, len) \ STMT_START { \ SV *TeMpSv = sv; \ sv_usepvn(TeMpSv,ptr,len); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef SvVSTRING_mg # define SvVSTRING_mg(sv) (SvMAGICAL(sv) ? mg_find(sv, PERL_MAGIC_vstring) : NULL) #endif /* Hint: sv_magic_portable * This is a compatibility function that is only available with * Devel::PPPort. It is NOT in the perl core. * Its purpose is to mimic the 5.8.0 behaviour of sv_magic() when * it is being passed a name pointer with namlen == 0. In that * case, perl 5.8.0 and later store the pointer, not a copy of it. * The compatibility can be provided back to perl 5.004. With * earlier versions, the code will not compile. */ #if (PERL_BCDVERSION < 0x5004000) /* code that uses sv_magic_portable will not compile */ #elif (PERL_BCDVERSION < 0x5008000) # define sv_magic_portable(sv, obj, how, name, namlen) \ STMT_START { \ SV *SvMp_sv = (sv); \ char *SvMp_name = (char *) (name); \ I32 SvMp_namlen = (namlen); \ if (SvMp_name && SvMp_namlen == 0) \ { \ MAGIC *mg; \ sv_magic(SvMp_sv, obj, how, 0, 0); \ mg = SvMAGIC(SvMp_sv); \ mg->mg_len = -42; /* XXX: this is the tricky part */ \ mg->mg_ptr = SvMp_name; \ } \ else \ { \ sv_magic(SvMp_sv, obj, how, SvMp_name, SvMp_namlen); \ } \ } STMT_END #else # define sv_magic_portable(a, b, c, d, e) sv_magic(a, b, c, d, e) #endif #if !defined(mg_findext) #if defined(NEED_mg_findext) static MAGIC * DPPP_(my_mg_findext)(SV * sv, int type, const MGVTBL *vtbl); static #else extern MAGIC * DPPP_(my_mg_findext)(SV * sv, int type, const MGVTBL *vtbl); #endif #if defined(NEED_mg_findext) || defined(NEED_mg_findext_GLOBAL) #define mg_findext DPPP_(my_mg_findext) #define Perl_mg_findext DPPP_(my_mg_findext) MAGIC * DPPP_(my_mg_findext)(SV * sv, int type, const MGVTBL *vtbl) { if (sv) { MAGIC *mg; #ifdef AvPAD_NAMELIST assert(!(SvTYPE(sv) == SVt_PVAV && AvPAD_NAMELIST(sv))); #endif for (mg = SvMAGIC (sv); mg; mg = mg->mg_moremagic) { if (mg->mg_type == type && mg->mg_virtual == vtbl) return mg; } } return NULL; } #endif #endif #if !defined(sv_unmagicext) #if defined(NEED_sv_unmagicext) static int DPPP_(my_sv_unmagicext)(pTHX_ SV * const sv, const int type, MGVTBL * vtbl); static #else extern int DPPP_(my_sv_unmagicext)(pTHX_ SV * const sv, const int type, MGVTBL * vtbl); #endif #if defined(NEED_sv_unmagicext) || defined(NEED_sv_unmagicext_GLOBAL) #ifdef sv_unmagicext # undef sv_unmagicext #endif #define sv_unmagicext(a,b,c) DPPP_(my_sv_unmagicext)(aTHX_ a,b,c) #define Perl_sv_unmagicext DPPP_(my_sv_unmagicext) int DPPP_(my_sv_unmagicext)(pTHX_ SV *const sv, const int type, MGVTBL *vtbl) { MAGIC* mg; MAGIC** mgp; if (SvTYPE(sv) < SVt_PVMG || !SvMAGIC(sv)) return 0; mgp = &(SvMAGIC(sv)); for (mg = *mgp; mg; mg = *mgp) { const MGVTBL* const virt = mg->mg_virtual; if (mg->mg_type == type && virt == vtbl) { *mgp = mg->mg_moremagic; if (virt && virt->svt_free) virt->svt_free(aTHX_ sv, mg); if (mg->mg_ptr && mg->mg_type != PERL_MAGIC_regex_global) { if (mg->mg_len > 0) Safefree(mg->mg_ptr); else if (mg->mg_len == HEf_SVKEY) /* Questionable on older perls... */ SvREFCNT_dec(MUTABLE_SV(mg->mg_ptr)); else if (mg->mg_type == PERL_MAGIC_utf8) Safefree(mg->mg_ptr); } if (mg->mg_flags & MGf_REFCOUNTED) SvREFCNT_dec(mg->mg_obj); Safefree(mg); } else mgp = &mg->mg_moremagic; } if (SvMAGIC(sv)) { if (SvMAGICAL(sv)) /* if we're under save_magic, wait for restore_magic; */ mg_magical(sv); /* else fix the flags now */ } else { SvMAGICAL_off(sv); SvFLAGS(sv) |= (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT; } return 0; } #endif #endif #ifdef USE_ITHREADS #ifndef CopFILE # define CopFILE(c) ((c)->cop_file) #endif #ifndef CopFILEGV # define CopFILEGV(c) (CopFILE(c) ? gv_fetchfile(CopFILE(c)) : Nullgv) #endif #ifndef CopFILE_set # define CopFILE_set(c,pv) ((c)->cop_file = savepv(pv)) #endif #ifndef CopFILESV # define CopFILESV(c) (CopFILE(c) ? GvSV(gv_fetchfile(CopFILE(c))) : Nullsv) #endif #ifndef CopFILEAV # define CopFILEAV(c) (CopFILE(c) ? GvAV(gv_fetchfile(CopFILE(c))) : Nullav) #endif #ifndef CopSTASHPV # define CopSTASHPV(c) ((c)->cop_stashpv) #endif #ifndef CopSTASHPV_set # define CopSTASHPV_set(c,pv) ((c)->cop_stashpv = ((pv) ? savepv(pv) : Nullch)) #endif #ifndef CopSTASH # define CopSTASH(c) (CopSTASHPV(c) ? gv_stashpv(CopSTASHPV(c),GV_ADD) : Nullhv) #endif #ifndef CopSTASH_set # define CopSTASH_set(c,hv) CopSTASHPV_set(c, (hv) ? HvNAME(hv) : Nullch) #endif #ifndef CopSTASH_eq # define CopSTASH_eq(c,hv) ((hv) && (CopSTASHPV(c) == HvNAME(hv) \ || (CopSTASHPV(c) && HvNAME(hv) \ && strEQ(CopSTASHPV(c), HvNAME(hv))))) #endif #else #ifndef CopFILEGV # define CopFILEGV(c) ((c)->cop_filegv) #endif #ifndef CopFILEGV_set # define CopFILEGV_set(c,gv) ((c)->cop_filegv = (GV*)SvREFCNT_inc(gv)) #endif #ifndef CopFILE_set # define CopFILE_set(c,pv) CopFILEGV_set((c), gv_fetchfile(pv)) #endif #ifndef CopFILESV # define CopFILESV(c) (CopFILEGV(c) ? GvSV(CopFILEGV(c)) : Nullsv) #endif #ifndef CopFILEAV # define CopFILEAV(c) (CopFILEGV(c) ? GvAV(CopFILEGV(c)) : Nullav) #endif #ifndef CopFILE # define CopFILE(c) (CopFILESV(c) ? SvPVX(CopFILESV(c)) : Nullch) #endif #ifndef CopSTASH # define CopSTASH(c) ((c)->cop_stash) #endif #ifndef CopSTASH_set # define CopSTASH_set(c,hv) ((c)->cop_stash = (hv)) #endif #ifndef CopSTASHPV # define CopSTASHPV(c) (CopSTASH(c) ? HvNAME(CopSTASH(c)) : Nullch) #endif #ifndef CopSTASHPV_set # define CopSTASHPV_set(c,pv) CopSTASH_set((c), gv_stashpv(pv,GV_ADD)) #endif #ifndef CopSTASH_eq # define CopSTASH_eq(c,hv) (CopSTASH(c) == (hv)) #endif #endif /* USE_ITHREADS */ #if (PERL_BCDVERSION >= 0x5006000) #ifndef caller_cx # if defined(NEED_caller_cx) || defined(NEED_caller_cx_GLOBAL) static I32 DPPP_dopoptosub_at(const PERL_CONTEXT *cxstk, I32 startingblock) { I32 i; for (i = startingblock; i >= 0; i--) { register const PERL_CONTEXT * const cx = &cxstk[i]; switch (CxTYPE(cx)) { default: continue; case CXt_EVAL: case CXt_SUB: case CXt_FORMAT: return i; } } return i; } # endif # if defined(NEED_caller_cx) static const PERL_CONTEXT * DPPP_(my_caller_cx)(pTHX_ I32 count, const PERL_CONTEXT **dbcxp); static #else extern const PERL_CONTEXT * DPPP_(my_caller_cx)(pTHX_ I32 count, const PERL_CONTEXT **dbcxp); #endif #if defined(NEED_caller_cx) || defined(NEED_caller_cx_GLOBAL) #ifdef caller_cx # undef caller_cx #endif #define caller_cx(a,b) DPPP_(my_caller_cx)(aTHX_ a,b) #define Perl_caller_cx DPPP_(my_caller_cx) const PERL_CONTEXT * DPPP_(my_caller_cx)(pTHX_ I32 count, const PERL_CONTEXT **dbcxp) { register I32 cxix = DPPP_dopoptosub_at(cxstack, cxstack_ix); register const PERL_CONTEXT *cx; register const PERL_CONTEXT *ccstack = cxstack; const PERL_SI *top_si = PL_curstackinfo; for (;;) { /* we may be in a higher stacklevel, so dig down deeper */ while (cxix < 0 && top_si->si_type != PERLSI_MAIN) { top_si = top_si->si_prev; ccstack = top_si->si_cxstack; cxix = DPPP_dopoptosub_at(ccstack, top_si->si_cxix); } if (cxix < 0) return NULL; /* caller() should not report the automatic calls to &DB::sub */ if (PL_DBsub && GvCV(PL_DBsub) && cxix >= 0 && ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub)) count++; if (!count--) break; cxix = DPPP_dopoptosub_at(ccstack, cxix - 1); } cx = &ccstack[cxix]; if (dbcxp) *dbcxp = cx; if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) { const I32 dbcxix = DPPP_dopoptosub_at(ccstack, cxix - 1); /* We expect that ccstack[dbcxix] is CXt_SUB, anyway, the field below is defined for any cx. */ /* caller() should not report the automatic calls to &DB::sub */ if (PL_DBsub && GvCV(PL_DBsub) && dbcxix >= 0 && ccstack[dbcxix].blk_sub.cv == GvCV(PL_DBsub)) cx = &ccstack[dbcxix]; } return cx; } # endif #endif /* caller_cx */ #endif /* 5.6.0 */ #ifndef IN_PERL_COMPILETIME # define IN_PERL_COMPILETIME (PL_curcop == &PL_compiling) #endif #ifndef IN_LOCALE_RUNTIME # define IN_LOCALE_RUNTIME (PL_curcop->op_private & HINT_LOCALE) #endif #ifndef IN_LOCALE_COMPILETIME # define IN_LOCALE_COMPILETIME (PL_hints & HINT_LOCALE) #endif #ifndef IN_LOCALE # define IN_LOCALE (IN_PERL_COMPILETIME ? IN_LOCALE_COMPILETIME : IN_LOCALE_RUNTIME) #endif #ifndef IS_NUMBER_IN_UV # define IS_NUMBER_IN_UV 0x01 #endif #ifndef IS_NUMBER_GREATER_THAN_UV_MAX # define IS_NUMBER_GREATER_THAN_UV_MAX 0x02 #endif #ifndef IS_NUMBER_NOT_INT # define IS_NUMBER_NOT_INT 0x04 #endif #ifndef IS_NUMBER_NEG # define IS_NUMBER_NEG 0x08 #endif #ifndef IS_NUMBER_INFINITY # define IS_NUMBER_INFINITY 0x10 #endif #ifndef IS_NUMBER_NAN # define IS_NUMBER_NAN 0x20 #endif #ifndef GROK_NUMERIC_RADIX # define GROK_NUMERIC_RADIX(sp, send) grok_numeric_radix(sp, send) #endif #ifndef PERL_SCAN_GREATER_THAN_UV_MAX # define PERL_SCAN_GREATER_THAN_UV_MAX 0x02 #endif #ifndef PERL_SCAN_SILENT_ILLDIGIT # define PERL_SCAN_SILENT_ILLDIGIT 0x04 #endif #ifndef PERL_SCAN_ALLOW_UNDERSCORES # define PERL_SCAN_ALLOW_UNDERSCORES 0x01 #endif #ifndef PERL_SCAN_DISALLOW_PREFIX # define PERL_SCAN_DISALLOW_PREFIX 0x02 #endif #ifndef grok_numeric_radix #if defined(NEED_grok_numeric_radix) static bool DPPP_(my_grok_numeric_radix)(pTHX_ const char ** sp, const char * send); static #else extern bool DPPP_(my_grok_numeric_radix)(pTHX_ const char ** sp, const char * send); #endif #if defined(NEED_grok_numeric_radix) || defined(NEED_grok_numeric_radix_GLOBAL) #ifdef grok_numeric_radix # undef grok_numeric_radix #endif #define grok_numeric_radix(a,b) DPPP_(my_grok_numeric_radix)(aTHX_ a,b) #define Perl_grok_numeric_radix DPPP_(my_grok_numeric_radix) bool DPPP_(my_grok_numeric_radix)(pTHX_ const char **sp, const char *send) { #ifdef USE_LOCALE_NUMERIC #ifdef PL_numeric_radix_sv if (PL_numeric_radix_sv && IN_LOCALE) { STRLEN len; char* radix = SvPV(PL_numeric_radix_sv, len); if (*sp + len <= send && memEQ(*sp, radix, len)) { *sp += len; return TRUE; } } #else /* older perls don't have PL_numeric_radix_sv so the radix * must manually be requested from locale.h */ #include dTHR; /* needed for older threaded perls */ struct lconv *lc = localeconv(); char *radix = lc->decimal_point; if (radix && IN_LOCALE) { STRLEN len = strlen(radix); if (*sp + len <= send && memEQ(*sp, radix, len)) { *sp += len; return TRUE; } } #endif #endif /* USE_LOCALE_NUMERIC */ /* always try "." if numeric radix didn't match because * we may have data from different locales mixed */ if (*sp < send && **sp == '.') { ++*sp; return TRUE; } return FALSE; } #endif #endif #ifndef grok_number #if defined(NEED_grok_number) static int DPPP_(my_grok_number)(pTHX_ const char * pv, STRLEN len, UV * valuep); static #else extern int DPPP_(my_grok_number)(pTHX_ const char * pv, STRLEN len, UV * valuep); #endif #if defined(NEED_grok_number) || defined(NEED_grok_number_GLOBAL) #ifdef grok_number # undef grok_number #endif #define grok_number(a,b,c) DPPP_(my_grok_number)(aTHX_ a,b,c) #define Perl_grok_number DPPP_(my_grok_number) int DPPP_(my_grok_number)(pTHX_ const char *pv, STRLEN len, UV *valuep) { const char *s = pv; const char *send = pv + len; const UV max_div_10 = UV_MAX / 10; const char max_mod_10 = UV_MAX % 10; int numtype = 0; int sawinf = 0; int sawnan = 0; while (s < send && isSPACE(*s)) s++; if (s == send) { return 0; } else if (*s == '-') { s++; numtype = IS_NUMBER_NEG; } else if (*s == '+') s++; if (s == send) return 0; /* next must be digit or the radix separator or beginning of infinity */ if (isDIGIT(*s)) { /* UVs are at least 32 bits, so the first 9 decimal digits cannot overflow. */ UV value = *s - '0'; /* This construction seems to be more optimiser friendly. (without it gcc does the isDIGIT test and the *s - '0' separately) With it gcc on arm is managing 6 instructions (6 cycles) per digit. In theory the optimiser could deduce how far to unroll the loop before checking for overflow. */ if (++s < send) { int digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { /* Now got 9 digits, so need to check each time for overflow. */ digit = *s - '0'; while (digit >= 0 && digit <= 9 && (value < max_div_10 || (value == max_div_10 && digit <= max_mod_10))) { value = value * 10 + digit; if (++s < send) digit = *s - '0'; else break; } if (digit >= 0 && digit <= 9 && (s < send)) { /* value overflowed. skip the remaining digits, don't worry about setting *valuep. */ do { s++; } while (s < send && isDIGIT(*s)); numtype |= IS_NUMBER_GREATER_THAN_UV_MAX; goto skip_value; } } } } } } } } } } } } } } } } } } numtype |= IS_NUMBER_IN_UV; if (valuep) *valuep = value; skip_value: if (GROK_NUMERIC_RADIX(&s, send)) { numtype |= IS_NUMBER_NOT_INT; while (s < send && isDIGIT(*s)) /* optional digits after the radix */ s++; } } else if (GROK_NUMERIC_RADIX(&s, send)) { numtype |= IS_NUMBER_NOT_INT | IS_NUMBER_IN_UV; /* valuep assigned below */ /* no digits before the radix means we need digits after it */ if (s < send && isDIGIT(*s)) { do { s++; } while (s < send && isDIGIT(*s)); if (valuep) { /* integer approximation is valid - it's 0. */ *valuep = 0; } } else return 0; } else if (*s == 'I' || *s == 'i') { s++; if (s == send || (*s != 'N' && *s != 'n')) return 0; s++; if (s == send || (*s != 'F' && *s != 'f')) return 0; s++; if (s < send && (*s == 'I' || *s == 'i')) { s++; if (s == send || (*s != 'N' && *s != 'n')) return 0; s++; if (s == send || (*s != 'I' && *s != 'i')) return 0; s++; if (s == send || (*s != 'T' && *s != 't')) return 0; s++; if (s == send || (*s != 'Y' && *s != 'y')) return 0; s++; } sawinf = 1; } else if (*s == 'N' || *s == 'n') { /* XXX TODO: There are signaling NaNs and quiet NaNs. */ s++; if (s == send || (*s != 'A' && *s != 'a')) return 0; s++; if (s == send || (*s != 'N' && *s != 'n')) return 0; s++; sawnan = 1; } else return 0; if (sawinf) { numtype &= IS_NUMBER_NEG; /* Keep track of sign */ numtype |= IS_NUMBER_INFINITY | IS_NUMBER_NOT_INT; } else if (sawnan) { numtype &= IS_NUMBER_NEG; /* Keep track of sign */ numtype |= IS_NUMBER_NAN | IS_NUMBER_NOT_INT; } else if (s < send) { /* we can have an optional exponent part */ if (*s == 'e' || *s == 'E') { /* The only flag we keep is sign. Blow away any "it's UV" */ numtype &= IS_NUMBER_NEG; numtype |= IS_NUMBER_NOT_INT; s++; if (s < send && (*s == '-' || *s == '+')) s++; if (s < send && isDIGIT(*s)) { do { s++; } while (s < send && isDIGIT(*s)); } else return 0; } } while (s < send && isSPACE(*s)) s++; if (s >= send) return numtype; if (len == 10 && memEQ(pv, "0 but true", 10)) { if (valuep) *valuep = 0; return IS_NUMBER_IN_UV; } return 0; } #endif #endif /* * The grok_* routines have been modified to use warn() instead of * Perl_warner(). Also, 'hexdigit' was the former name of PL_hexdigit, * which is why the stack variable has been renamed to 'xdigit'. */ #ifndef grok_bin #if defined(NEED_grok_bin) static UV DPPP_(my_grok_bin)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); static #else extern UV DPPP_(my_grok_bin)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); #endif #if defined(NEED_grok_bin) || defined(NEED_grok_bin_GLOBAL) #ifdef grok_bin # undef grok_bin #endif #define grok_bin(a,b,c,d) DPPP_(my_grok_bin)(aTHX_ a,b,c,d) #define Perl_grok_bin DPPP_(my_grok_bin) UV DPPP_(my_grok_bin)(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) { const char *s = start; STRLEN len = *len_p; UV value = 0; NV value_nv = 0; const UV max_div_2 = UV_MAX / 2; bool allow_underscores = *flags & PERL_SCAN_ALLOW_UNDERSCORES; bool overflowed = FALSE; if (!(*flags & PERL_SCAN_DISALLOW_PREFIX)) { /* strip off leading b or 0b. for compatibility silently suffer "b" and "0b" as valid binary numbers. */ if (len >= 1) { if (s[0] == 'b') { s++; len--; } else if (len >= 2 && s[0] == '0' && s[1] == 'b') { s+=2; len-=2; } } } for (; len-- && *s; s++) { char bit = *s; if (bit == '0' || bit == '1') { /* Write it in this wonky order with a goto to attempt to get the compiler to make the common case integer-only loop pretty tight. With gcc seems to be much straighter code than old scan_bin. */ redo: if (!overflowed) { if (value <= max_div_2) { value = (value << 1) | (bit - '0'); continue; } /* Bah. We're just overflowed. */ warn("Integer overflow in binary number"); overflowed = TRUE; value_nv = (NV) value; } value_nv *= 2.0; /* If an NV has not enough bits in its mantissa to * represent a UV this summing of small low-order numbers * is a waste of time (because the NV cannot preserve * the low-order bits anyway): we could just remember when * did we overflow and in the end just multiply value_nv by the * right amount. */ value_nv += (NV)(bit - '0'); continue; } if (bit == '_' && len && allow_underscores && (bit = s[1]) && (bit == '0' || bit == '1')) { --len; ++s; goto redo; } if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT)) warn("Illegal binary digit '%c' ignored", *s); break; } if ( ( overflowed && value_nv > 4294967295.0) #if UVSIZE > 4 || (!overflowed && value > 0xffffffff ) #endif ) { warn("Binary number > 0b11111111111111111111111111111111 non-portable"); } *len_p = s - start; if (!overflowed) { *flags = 0; return value; } *flags = PERL_SCAN_GREATER_THAN_UV_MAX; if (result) *result = value_nv; return UV_MAX; } #endif #endif #ifndef grok_hex #if defined(NEED_grok_hex) static UV DPPP_(my_grok_hex)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); static #else extern UV DPPP_(my_grok_hex)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); #endif #if defined(NEED_grok_hex) || defined(NEED_grok_hex_GLOBAL) #ifdef grok_hex # undef grok_hex #endif #define grok_hex(a,b,c,d) DPPP_(my_grok_hex)(aTHX_ a,b,c,d) #define Perl_grok_hex DPPP_(my_grok_hex) UV DPPP_(my_grok_hex)(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) { const char *s = start; STRLEN len = *len_p; UV value = 0; NV value_nv = 0; const UV max_div_16 = UV_MAX / 16; bool allow_underscores = *flags & PERL_SCAN_ALLOW_UNDERSCORES; bool overflowed = FALSE; const char *xdigit; if (!(*flags & PERL_SCAN_DISALLOW_PREFIX)) { /* strip off leading x or 0x. for compatibility silently suffer "x" and "0x" as valid hex numbers. */ if (len >= 1) { if (s[0] == 'x') { s++; len--; } else if (len >= 2 && s[0] == '0' && s[1] == 'x') { s+=2; len-=2; } } } for (; len-- && *s; s++) { xdigit = strchr((char *) PL_hexdigit, *s); if (xdigit) { /* Write it in this wonky order with a goto to attempt to get the compiler to make the common case integer-only loop pretty tight. With gcc seems to be much straighter code than old scan_hex. */ redo: if (!overflowed) { if (value <= max_div_16) { value = (value << 4) | ((xdigit - PL_hexdigit) & 15); continue; } warn("Integer overflow in hexadecimal number"); overflowed = TRUE; value_nv = (NV) value; } value_nv *= 16.0; /* If an NV has not enough bits in its mantissa to * represent a UV this summing of small low-order numbers * is a waste of time (because the NV cannot preserve * the low-order bits anyway): we could just remember when * did we overflow and in the end just multiply value_nv by the * right amount of 16-tuples. */ value_nv += (NV)((xdigit - PL_hexdigit) & 15); continue; } if (*s == '_' && len && allow_underscores && s[1] && (xdigit = strchr((char *) PL_hexdigit, s[1]))) { --len; ++s; goto redo; } if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT)) warn("Illegal hexadecimal digit '%c' ignored", *s); break; } if ( ( overflowed && value_nv > 4294967295.0) #if UVSIZE > 4 || (!overflowed && value > 0xffffffff ) #endif ) { warn("Hexadecimal number > 0xffffffff non-portable"); } *len_p = s - start; if (!overflowed) { *flags = 0; return value; } *flags = PERL_SCAN_GREATER_THAN_UV_MAX; if (result) *result = value_nv; return UV_MAX; } #endif #endif #ifndef grok_oct #if defined(NEED_grok_oct) static UV DPPP_(my_grok_oct)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); static #else extern UV DPPP_(my_grok_oct)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); #endif #if defined(NEED_grok_oct) || defined(NEED_grok_oct_GLOBAL) #ifdef grok_oct # undef grok_oct #endif #define grok_oct(a,b,c,d) DPPP_(my_grok_oct)(aTHX_ a,b,c,d) #define Perl_grok_oct DPPP_(my_grok_oct) UV DPPP_(my_grok_oct)(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) { const char *s = start; STRLEN len = *len_p; UV value = 0; NV value_nv = 0; const UV max_div_8 = UV_MAX / 8; bool allow_underscores = *flags & PERL_SCAN_ALLOW_UNDERSCORES; bool overflowed = FALSE; for (; len-- && *s; s++) { /* gcc 2.95 optimiser not smart enough to figure that this subtraction out front allows slicker code. */ int digit = *s - '0'; if (digit >= 0 && digit <= 7) { /* Write it in this wonky order with a goto to attempt to get the compiler to make the common case integer-only loop pretty tight. */ redo: if (!overflowed) { if (value <= max_div_8) { value = (value << 3) | digit; continue; } /* Bah. We're just overflowed. */ warn("Integer overflow in octal number"); overflowed = TRUE; value_nv = (NV) value; } value_nv *= 8.0; /* If an NV has not enough bits in its mantissa to * represent a UV this summing of small low-order numbers * is a waste of time (because the NV cannot preserve * the low-order bits anyway): we could just remember when * did we overflow and in the end just multiply value_nv by the * right amount of 8-tuples. */ value_nv += (NV)digit; continue; } if (digit == ('_' - '0') && len && allow_underscores && (digit = s[1] - '0') && (digit >= 0 && digit <= 7)) { --len; ++s; goto redo; } /* Allow \octal to work the DWIM way (that is, stop scanning * as soon as non-octal characters are seen, complain only iff * someone seems to want to use the digits eight and nine). */ if (digit == 8 || digit == 9) { if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT)) warn("Illegal octal digit '%c' ignored", *s); } break; } if ( ( overflowed && value_nv > 4294967295.0) #if UVSIZE > 4 || (!overflowed && value > 0xffffffff ) #endif ) { warn("Octal number > 037777777777 non-portable"); } *len_p = s - start; if (!overflowed) { *flags = 0; return value; } *flags = PERL_SCAN_GREATER_THAN_UV_MAX; if (result) *result = value_nv; return UV_MAX; } #endif #endif #if !defined(my_snprintf) #if defined(NEED_my_snprintf) static int DPPP_(my_my_snprintf)(char * buffer, const Size_t len, const char * format, ...); static #else extern int DPPP_(my_my_snprintf)(char * buffer, const Size_t len, const char * format, ...); #endif #if defined(NEED_my_snprintf) || defined(NEED_my_snprintf_GLOBAL) #define my_snprintf DPPP_(my_my_snprintf) #define Perl_my_snprintf DPPP_(my_my_snprintf) int DPPP_(my_my_snprintf)(char *buffer, const Size_t len, const char *format, ...) { dTHX; int retval; va_list ap; va_start(ap, format); #ifdef HAS_VSNPRINTF retval = vsnprintf(buffer, len, format, ap); #else retval = vsprintf(buffer, format, ap); #endif va_end(ap); if (retval < 0 || (len > 0 && (Size_t)retval >= len)) Perl_croak(aTHX_ "panic: my_snprintf buffer overflow"); return retval; } #endif #endif #if !defined(my_sprintf) #if defined(NEED_my_sprintf) static int DPPP_(my_my_sprintf)(char * buffer, const char * pat, ...); static #else extern int DPPP_(my_my_sprintf)(char * buffer, const char * pat, ...); #endif #if defined(NEED_my_sprintf) || defined(NEED_my_sprintf_GLOBAL) #define my_sprintf DPPP_(my_my_sprintf) #define Perl_my_sprintf DPPP_(my_my_sprintf) int DPPP_(my_my_sprintf)(char *buffer, const char* pat, ...) { va_list args; va_start(args, pat); vsprintf(buffer, pat, args); va_end(args); return strlen(buffer); } #endif #endif #ifdef NO_XSLOCKS # ifdef dJMPENV # define dXCPT dJMPENV; int rEtV = 0 # define XCPT_TRY_START JMPENV_PUSH(rEtV); if (rEtV == 0) # define XCPT_TRY_END JMPENV_POP; # define XCPT_CATCH if (rEtV != 0) # define XCPT_RETHROW JMPENV_JUMP(rEtV) # else # define dXCPT Sigjmp_buf oldTOP; int rEtV = 0 # define XCPT_TRY_START Copy(top_env, oldTOP, 1, Sigjmp_buf); rEtV = Sigsetjmp(top_env, 1); if (rEtV == 0) # define XCPT_TRY_END Copy(oldTOP, top_env, 1, Sigjmp_buf); # define XCPT_CATCH if (rEtV != 0) # define XCPT_RETHROW Siglongjmp(top_env, rEtV) # endif #endif #if !defined(my_strlcat) #if defined(NEED_my_strlcat) static Size_t DPPP_(my_my_strlcat)(char * dst, const char * src, Size_t size); static #else extern Size_t DPPP_(my_my_strlcat)(char * dst, const char * src, Size_t size); #endif #if defined(NEED_my_strlcat) || defined(NEED_my_strlcat_GLOBAL) #define my_strlcat DPPP_(my_my_strlcat) #define Perl_my_strlcat DPPP_(my_my_strlcat) Size_t DPPP_(my_my_strlcat)(char *dst, const char *src, Size_t size) { Size_t used, length, copy; used = strlen(dst); length = strlen(src); if (size > 0 && used < size - 1) { copy = (length >= size - used) ? size - used - 1 : length; memcpy(dst + used, src, copy); dst[used + copy] = '\0'; } return used + length; } #endif #endif #if !defined(my_strlcpy) #if defined(NEED_my_strlcpy) static Size_t DPPP_(my_my_strlcpy)(char * dst, const char * src, Size_t size); static #else extern Size_t DPPP_(my_my_strlcpy)(char * dst, const char * src, Size_t size); #endif #if defined(NEED_my_strlcpy) || defined(NEED_my_strlcpy_GLOBAL) #define my_strlcpy DPPP_(my_my_strlcpy) #define Perl_my_strlcpy DPPP_(my_my_strlcpy) Size_t DPPP_(my_my_strlcpy)(char *dst, const char *src, Size_t size) { Size_t length, copy; length = strlen(src); if (size > 0) { copy = (length >= size) ? size - 1 : length; memcpy(dst, src, copy); dst[copy] = '\0'; } return length; } #endif #endif #ifndef PERL_PV_ESCAPE_QUOTE # define PERL_PV_ESCAPE_QUOTE 0x0001 #endif #ifndef PERL_PV_PRETTY_QUOTE # define PERL_PV_PRETTY_QUOTE PERL_PV_ESCAPE_QUOTE #endif #ifndef PERL_PV_PRETTY_ELLIPSES # define PERL_PV_PRETTY_ELLIPSES 0x0002 #endif #ifndef PERL_PV_PRETTY_LTGT # define PERL_PV_PRETTY_LTGT 0x0004 #endif #ifndef PERL_PV_ESCAPE_FIRSTCHAR # define PERL_PV_ESCAPE_FIRSTCHAR 0x0008 #endif #ifndef PERL_PV_ESCAPE_UNI # define PERL_PV_ESCAPE_UNI 0x0100 #endif #ifndef PERL_PV_ESCAPE_UNI_DETECT # define PERL_PV_ESCAPE_UNI_DETECT 0x0200 #endif #ifndef PERL_PV_ESCAPE_ALL # define PERL_PV_ESCAPE_ALL 0x1000 #endif #ifndef PERL_PV_ESCAPE_NOBACKSLASH # define PERL_PV_ESCAPE_NOBACKSLASH 0x2000 #endif #ifndef PERL_PV_ESCAPE_NOCLEAR # define PERL_PV_ESCAPE_NOCLEAR 0x4000 #endif #ifndef PERL_PV_ESCAPE_RE # define PERL_PV_ESCAPE_RE 0x8000 #endif #ifndef PERL_PV_PRETTY_NOCLEAR # define PERL_PV_PRETTY_NOCLEAR PERL_PV_ESCAPE_NOCLEAR #endif #ifndef PERL_PV_PRETTY_DUMP # define PERL_PV_PRETTY_DUMP PERL_PV_PRETTY_ELLIPSES|PERL_PV_PRETTY_QUOTE #endif #ifndef PERL_PV_PRETTY_REGPROP # define PERL_PV_PRETTY_REGPROP PERL_PV_PRETTY_ELLIPSES|PERL_PV_PRETTY_LTGT|PERL_PV_ESCAPE_RE #endif /* Hint: pv_escape * Note that unicode functionality is only backported to * those perl versions that support it. For older perl * versions, the implementation will fall back to bytes. */ #ifndef pv_escape #if defined(NEED_pv_escape) static char * DPPP_(my_pv_escape)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, STRLEN * const escaped, const U32 flags); static #else extern char * DPPP_(my_pv_escape)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, STRLEN * const escaped, const U32 flags); #endif #if defined(NEED_pv_escape) || defined(NEED_pv_escape_GLOBAL) #ifdef pv_escape # undef pv_escape #endif #define pv_escape(a,b,c,d,e,f) DPPP_(my_pv_escape)(aTHX_ a,b,c,d,e,f) #define Perl_pv_escape DPPP_(my_pv_escape) char * DPPP_(my_pv_escape)(pTHX_ SV *dsv, char const * const str, const STRLEN count, const STRLEN max, STRLEN * const escaped, const U32 flags) { const char esc = flags & PERL_PV_ESCAPE_RE ? '%' : '\\'; const char dq = flags & PERL_PV_ESCAPE_QUOTE ? '"' : esc; char octbuf[32] = "%123456789ABCDF"; STRLEN wrote = 0; STRLEN chsize = 0; STRLEN readsize = 1; #if defined(is_utf8_string) && defined(utf8_to_uvchr) bool isuni = flags & PERL_PV_ESCAPE_UNI ? 1 : 0; #endif const char *pv = str; const char * const end = pv + count; octbuf[0] = esc; if (!(flags & PERL_PV_ESCAPE_NOCLEAR)) sv_setpvs(dsv, ""); #if defined(is_utf8_string) && defined(utf8_to_uvchr) if ((flags & PERL_PV_ESCAPE_UNI_DETECT) && is_utf8_string((U8*)pv, count)) isuni = 1; #endif for (; pv < end && (!max || wrote < max) ; pv += readsize) { const UV u = #if defined(is_utf8_string) && defined(utf8_to_uvchr) isuni ? utf8_to_uvchr((U8*)pv, &readsize) : #endif (U8)*pv; const U8 c = (U8)u & 0xFF; if (u > 255 || (flags & PERL_PV_ESCAPE_ALL)) { if (flags & PERL_PV_ESCAPE_FIRSTCHAR) chsize = my_snprintf(octbuf, sizeof octbuf, "%" UVxf, u); else chsize = my_snprintf(octbuf, sizeof octbuf, "%cx{%" UVxf "}", esc, u); } else if (flags & PERL_PV_ESCAPE_NOBACKSLASH) { chsize = 1; } else { if (c == dq || c == esc || !isPRINT(c)) { chsize = 2; switch (c) { case '\\' : /* fallthrough */ case '%' : if (c == esc) octbuf[1] = esc; else chsize = 1; break; case '\v' : octbuf[1] = 'v'; break; case '\t' : octbuf[1] = 't'; break; case '\r' : octbuf[1] = 'r'; break; case '\n' : octbuf[1] = 'n'; break; case '\f' : octbuf[1] = 'f'; break; case '"' : if (dq == '"') octbuf[1] = '"'; else chsize = 1; break; default: chsize = my_snprintf(octbuf, sizeof octbuf, pv < end && isDIGIT((U8)*(pv+readsize)) ? "%c%03o" : "%c%o", esc, c); } } else { chsize = 1; } } if (max && wrote + chsize > max) { break; } else if (chsize > 1) { sv_catpvn(dsv, octbuf, chsize); wrote += chsize; } else { char tmp[2]; my_snprintf(tmp, sizeof tmp, "%c", c); sv_catpvn(dsv, tmp, 1); wrote++; } if (flags & PERL_PV_ESCAPE_FIRSTCHAR) break; } if (escaped != NULL) *escaped= pv - str; return SvPVX(dsv); } #endif #endif #ifndef pv_pretty #if defined(NEED_pv_pretty) static char * DPPP_(my_pv_pretty)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, char const * const start_color, char const * const end_color, const U32 flags); static #else extern char * DPPP_(my_pv_pretty)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, char const * const start_color, char const * const end_color, const U32 flags); #endif #if defined(NEED_pv_pretty) || defined(NEED_pv_pretty_GLOBAL) #ifdef pv_pretty # undef pv_pretty #endif #define pv_pretty(a,b,c,d,e,f,g) DPPP_(my_pv_pretty)(aTHX_ a,b,c,d,e,f,g) #define Perl_pv_pretty DPPP_(my_pv_pretty) char * DPPP_(my_pv_pretty)(pTHX_ SV *dsv, char const * const str, const STRLEN count, const STRLEN max, char const * const start_color, char const * const end_color, const U32 flags) { const U8 dq = (flags & PERL_PV_PRETTY_QUOTE) ? '"' : '%'; STRLEN escaped; if (!(flags & PERL_PV_PRETTY_NOCLEAR)) sv_setpvs(dsv, ""); if (dq == '"') sv_catpvs(dsv, "\""); else if (flags & PERL_PV_PRETTY_LTGT) sv_catpvs(dsv, "<"); if (start_color != NULL) sv_catpv(dsv, D_PPP_CONSTPV_ARG(start_color)); pv_escape(dsv, str, count, max, &escaped, flags | PERL_PV_ESCAPE_NOCLEAR); if (end_color != NULL) sv_catpv(dsv, D_PPP_CONSTPV_ARG(end_color)); if (dq == '"') sv_catpvs(dsv, "\""); else if (flags & PERL_PV_PRETTY_LTGT) sv_catpvs(dsv, ">"); if ((flags & PERL_PV_PRETTY_ELLIPSES) && escaped < count) sv_catpvs(dsv, "..."); return SvPVX(dsv); } #endif #endif #ifndef pv_display #if defined(NEED_pv_display) static char * DPPP_(my_pv_display)(pTHX_ SV * dsv, const char * pv, STRLEN cur, STRLEN len, STRLEN pvlim); static #else extern char * DPPP_(my_pv_display)(pTHX_ SV * dsv, const char * pv, STRLEN cur, STRLEN len, STRLEN pvlim); #endif #if defined(NEED_pv_display) || defined(NEED_pv_display_GLOBAL) #ifdef pv_display # undef pv_display #endif #define pv_display(a,b,c,d,e) DPPP_(my_pv_display)(aTHX_ a,b,c,d,e) #define Perl_pv_display DPPP_(my_pv_display) char * DPPP_(my_pv_display)(pTHX_ SV *dsv, const char *pv, STRLEN cur, STRLEN len, STRLEN pvlim) { pv_pretty(dsv, pv, cur, pvlim, NULL, NULL, PERL_PV_PRETTY_DUMP); if (len > cur && pv[cur] == '\0') sv_catpvs(dsv, "\\0"); return SvPVX(dsv); } #endif #endif #endif /* _P_P_PORTABILITY_H_ */ /* End of File c/ppport.h */ tidyall.ini100644000000000000 216013321164704 16354 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003[PerlCritic] select = **/*.{pl,pm,t,psgi} ignore = .build/**/* ignore = MaxMind-DB-Writer-*/**/* ignore = blib/**/* ignore = dev-bin/**/* ignore = inc/Capture/**/* ignore = inc/Config/**/* ignore = t/00-* ignore = t/author-* ignore = t/release-* ignore = t/zzz-* ignore = xt/**/* argv = --profile=$ROOT/perlcriticrc [PerlCritic non-auto-generated xt] select = xt/author/Tree-freeze-thaw-large-tree.t argv = --profile=$ROOT/perlcriticrc [PerlTidy] select = **/*.{pl,pm,t,psgi} ignore = .build/**/* ignore = MaxMind-DB-Writer-*/**/* ignore = blib/**/* ignore = dev-bin/**/* ignore = inc/Capture/**/* ignore = inc/Config/**/* ignore = t/00-* ignore = t/author-* ignore = t/release-* ignore = t/zzz-* ignore = xt/**/* argv = --profile=$ROOT/perltidyrc [PerlTidy non-auto-generated xt] select = xt/author/Tree-freeze-thaw-large-tree.t argv = --profile=$ROOT/perltidyrc [Test::Vars] select = **/*.pm ignore = .build/**/* ignore = MaxMind-DB-Writer-*/**/* ignore = blib/**/* ignore = dev-bin/**/* ignore = inc/Capture/**/* ignore = inc/Config/**/* ignore = t/00-* ignore = t/author-* ignore = t/release-* ignore = t/zzz-* ignore = xt/**/* perlcriticrc100644000000000000 367113321164704 16631 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003severity = 3 verbose = 11 theme = core + pbp + bugs + maintenance + cosmetic + complexity + security + tests + moose program-extensions = pl psgi t exclude = Subroutines::ProhibitCallsToUndeclaredSubs [BuiltinFunctions::ProhibitStringySplit] severity = 3 [CodeLayout::RequireTrailingCommas] severity = 3 [ControlStructures::ProhibitCStyleForLoops] severity = 3 [InputOutput::RequireCheckedSyscalls] functions = :builtins exclude_functions = sleep severity = 3 [RegularExpressions::ProhibitComplexRegexes] max_characters = 200 [RegularExpressions::ProhibitUnusualDelimiters] severity = 3 [Subroutines::ProhibitUnusedPrivateSubroutines] private_name_regex = _(?!build)\w+ [TestingAndDebugging::ProhibitNoWarnings] allow = redefine [ValuesAndExpressions::ProhibitEmptyQuotes] severity = 3 [ValuesAndExpressions::ProhibitInterpolationOfLiterals] severity = 3 [ValuesAndExpressions::RequireUpperCaseHeredocTerminator] severity = 3 [Variables::ProhibitPackageVars] add_packages = Carp Test::Builder [-Subroutines::RequireFinalReturn] # This incorrectly thinks signatures are prototypes. [-Subroutines::ProhibitSubroutinePrototypes] [-ErrorHandling::RequireCarping] # No need for /xsm everywhere [-RegularExpressions::RequireDotMatchAnything] [-RegularExpressions::RequireExtendedFormatting] [-RegularExpressions::RequireLineBoundaryMatching] # http://stackoverflow.com/questions/2275317/why-does-perlcritic-dislike-using-shift-to-populate-subroutine-variables [-Subroutines::RequireArgUnpacking] # "use v5.14" is more readable than "use 5.014" [-ValuesAndExpressions::ProhibitVersionStrings] # Explicitly returning undef is a _good_ thing in many cases, since it # prevents very common errors when using a sub in list context to construct a # hash and ending up with a missing value or key. [-Subroutines::ProhibitExplicitReturnUndef] # Sometimes I want to write "return unless $x > 4" [-ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions] valgrind.supp100644000000000000 3023013321164704 16747 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003{ perl core parse leak Memcheck:Leak fun:malloc fun:Perl_safesysmalloc fun:Perl_bytes_from_utf8 fun:Perl_pad_add_name_pvn fun:Perl_allocmy fun:Perl_yylex fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize } { perl core parse leak Memcheck:Leak fun:malloc fun:Perl_safesysmalloc fun:Perl_bytes_from_utf8 fun:Perl_pad_add_name_pvn fun:Perl_allocmy fun:Perl_yylex fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize } { perl core parse leak Memcheck:Leak fun:malloc fun:Perl_safesysmalloc fun:Perl_savepv fun:Perl_newXS_len_flags fun:Perl_newCONSTSUB_flags fun:Perl_gv_init_pvn fun:Perl_gv_fetchpvn_flags fun:Perl_gv_fetchsv fun:Perl_ck_rvconst fun:Perl_newUNOP fun:Perl_yylex fun:Perl_yyparse fun:S_doeval fun:Perl_pp_entereval fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse fun:perl_parse fun:main } { perl core parse leak Memcheck:Leak fun:malloc fun:Perl_safesysmalloc fun:Perl_bytes_from_utf8 fun:Perl_pad_findmy_pvn fun:Perl_yylex fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse } { perl core parse leak Memcheck:Leak fun:malloc fun:Perl_safesysmalloc fun:Perl_savepv fun:Perl_newXS_len_flags fun:Perl_newCONSTSUB_flags fun:Perl_gv_init_pvn fun:Perl_gv_fetchpvn_flags fun:S_intuit_method fun:Perl_yylex fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list } { perl core parse leak Memcheck:Leak fun:calloc fun:Perl_newSVOP fun:Perl_yylex fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse fun:perl_parse fun:main } { perl core parse leak Memcheck:Leak fun:calloc fun:Perl_newSVOP fun:Perl_yylex fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:S_curse fun:Perl_sv_clear fun:Perl_sv_free2 fun:Perl_free_tmps fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks } { perl core parse leak Memcheck:Leak fun:calloc fun:Perl_newSVOP fun:Perl_yylex fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require } { perl core parse leak Memcheck:Leak fun:malloc fun:Perl_safesysmalloc fun:Perl_savepv fun:Perl_newXS_len_flags fun:Perl_newCONSTSUB_flags fun:Perl_gv_init_pvn fun:Perl_gv_fetchpvn_flags fun:Perl_yylex fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse fun:perl_parse fun:main } { perl core parse leak Memcheck:Leak fun:malloc fun:Perl_safesysmalloc fun:Perl_savepv fun:Perl_newXS_len_flags fun:Perl_newCONSTSUB_flags fun:Perl_gv_init_pvn fun:Perl_gv_fetchpvn_flags fun:Perl_get_cvn_flags fun:Perl_pp_entersub fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse fun:perl_parse } { perl core parse leak Memcheck:Leak fun:malloc fun:Perl_safesysmalloc fun:Perl_savepv fun:Perl_newXS_len_flags fun:Perl_newCONSTSUB_flags fun:Perl_gv_init_pvn fun:mop_get_package_symbols fun:mop_get_all_package_symbols fun:XS_Class__MOP__Mixin__HasMethods__method_map fun:Perl_pp_entersub fun:Perl_runops_standard fun:Perl_call_sv fun:vmg_call_sv.constprop.4 fun:vmg_svt_free fun:S_mg_free_struct fun:Perl_mg_free fun:Perl_sv_clear fun:Perl_sv_free2 fun:Perl_leave_scope fun:Perl_block_end fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard } { perl core parse leak Memcheck:Leak fun:malloc fun:Perl_safesysmalloc fun:Perl_bytes_from_utf8 fun:Perl_pad_add_name_pvn fun:Perl_allocmy fun:Perl_yylex fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse fun:perl_parse fun:main } { perl core parse leak Memcheck:Leak fun:malloc fun:Perl_safesysmalloc fun:Perl_bytes_from_utf8 fun:Perl_pad_add_name_pvn fun:Perl_allocmy fun:Perl_yylex fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse fun:perl_parse fun:main } { perl core parse leak Memcheck:Leak fun:malloc fun:Perl_safesysmalloc fun:Perl_bytes_from_utf8 fun:Perl_pad_findmy_pvn fun:Perl_yylex fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse fun:perl_parse fun:main } { Moose leak? Memcheck:Leak fun:malloc fun:Perl_safesysmalloc fun:Perl_savepv fun:Perl_newXS_len_flags fun:Perl_newCONSTSUB_flags fun:Perl_gv_init_pvn fun:mop_get_package_symbols fun:mop_get_all_package_symbols fun:XS_Class__MOP__Mixin__HasMethods__method_map fun:Perl_pp_entersub fun:Perl_runops_standard fun:Perl_call_sv fun:vmg_call_sv.constprop.4 fun:vmg_svt_free fun:S_mg_free_struct fun:Perl_mg_free fun:Perl_sv_clear fun:Perl_sv_free2 fun:Perl_leave_scope fun:Perl_block_end fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard } { perl core parse leak Memcheck:Leak fun:malloc fun:Perl_safesysmalloc fun:Perl_savepv fun:Perl_newXS_len_flags fun:Perl_newCONSTSUB_flags fun:Perl_gv_init_pvn fun:Perl_gv_fetchpvn_flags fun:Perl_gv_fetchsv fun:Perl_ck_rvconst fun:Perl_newUNOP fun:Perl_yylex fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard } { perl core parse leak Memcheck:Leak fun:malloc fun:Perl_safesysmalloc fun:Perl_savepv fun:Perl_newXS_len_flags fun:Perl_newCONSTSUB_flags fun:Perl_gv_init_pvn fun:Perl_gv_fetchpvn_flags fun:Perl_gv_fetchsv fun:Perl_ck_rvconst fun:Perl_newUNOP fun:Perl_yylex fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard } { perl require leak Memcheck:Leak fun:malloc fun:Perl_safesysmalloc fun:Perl_savepv fun:Perl_newXS_len_flags fun:Perl_newCONSTSUB_flags fun:Perl_gv_init_pvn fun:Perl_gv_fetchpvn_flags fun:Perl_gv_fetchsv fun:Perl_ck_rvconst fun:Perl_newUNOP fun:Perl_yylex fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard } { perl core parse leak Memcheck:Leak fun:malloc fun:Perl_safesysmalloc fun:Perl_savepv fun:Perl_newXS_len_flags fun:Perl_newCONSTSUB_flags fun:Perl_gv_init_pvn fun:Perl_gv_fetchpvn_flags fun:Perl_gv_fetchsv fun:Perl_ck_rvconst fun:Perl_newUNOP fun:Perl_yylex fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse fun:perl_parse fun:main } { perl core parse leak Memcheck:Leak fun:malloc fun:Perl_safesysmalloc fun:Perl_savepv fun:Perl_newXS_len_flags fun:Perl_newCONSTSUB_flags fun:Perl_gv_init_pvn fun:Perl_gv_fetchpvn_flags fun:Perl_gv_fetchsv fun:Perl_ck_rvconst fun:Perl_newUNOP fun:Perl_yylex fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard } { Moose mop.c memory leak Memcheck:Leak fun:malloc fun:Perl_safesysmalloc fun:Perl_savepv fun:Perl_newXS_len_flags fun:Perl_newCONSTSUB_flags fun:Perl_gv_init_pvn fun:mop_get_package_symbols fun:mop_get_all_package_symbols fun:XS_Class__MOP__Mixin__HasMethods__method_map fun:Perl_pp_entersub fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags fun:Perl_utilize fun:Perl_yyparse fun:S_doeval fun:Perl_pp_require fun:Perl_runops_standard fun:Perl_call_sv fun:Perl_call_list fun:S_process_special_blocks fun:Perl_newATTRSUB_flags } { gaih_inet Condition jump on unitialised value(s) Memcheck:Cond fun:gaih_inet fun:getaddrinfo fun:resolve_network fun:insert_network fun:XS_MaxMind__DB__Writer__Tree__insert_network fun:Perl_pp_entersub fun:Perl_runops_standard fun:perl_run fun:main } { gaih_inet Condition jump on unitialised value(s) Memcheck:Cond fun:gaih_inet fun:getaddrinfo fun:resolve_network fun:alias_ipv4_networks fun:write_search_tree fun:XS_MaxMind__DB__Writer__Tree__write_search_tree fun:Perl_pp_entersub fun:Perl_runops_standard fun:perl_run fun:main } eg000755000000000000 013321164704 14445 5ustar00rootroot000000000000MaxMind-DB-Writer-0.300003freeze-thaw100644000000000000 417613321164704 16761 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/eguse strict; use warnings; use v5.16; use utf8; use Math::Int128 qw( uint128 ); use MaxMind::DB::Writer::Tree; use Net::Works::Network; use Timer::Simple; my $cb = sub { my $key = $_[0]; $key =~ s/X$//; return $key eq 'array' ? [ 'array', 'uint32' ] : $key; }; my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test tree' }, merge_record_collisions => 1, map_key_type_callback => $cb, ); my $s = Timer::Simple->new( start => 1 ); my $count = int( 2**15 * 1.6 ); for my $i ( 1 .. $count ) { my $n = Net::Works::Network->new_from_integer( integer => $i, prefix_length => 128, version => 6 ); $tree->insert_network( $n, _data_record( $i % 16 ) ); } $s->stop(); print "Built in-memory tree of $count networks in ", $s->elapsed, " seconds\n"; $s->start(); open my $fh1, '>', 'tree1'; $tree->write_tree($fh1); $s->stop(); print "Wrote tree to disk in ", $s->elapsed, " seconds\n"; $s->start(); my $file = './frozen'; $tree->freeze_tree($file); $s->stop(); print "Frozen tree to disk in ", $s->elapsed, " seconds\n"; $s->start(); my $tree2 = MaxMind::DB::Writer::Tree->from_frozen_tree( $file, $cb ); $s->stop(); print "Thawed tree in ", $s->elapsed, " seconds\n"; $s->start(); open my $fh2, '>', 'tree2'; $tree2->write_tree($fh2); sub _data_record { my $i = shift; return { utf8_string => 'unicode! ☯ - ♫ - ' . $i, double => 42.123456 + $i, bytes => pack( 'N', 42 + $i ), uint16 => 100 + $i, uint32 => 2**28 + $i, int32 => -1 * ( 2**28 + $i ), uint64 => ( uint128(1) << 60 ) + $i, uint128 => ( uint128(1) << 120 ) + $i, array => [ 1, 2, 3, $i ], map => { mapX => { utf8_stringX => 'hello - ' . $i, arrayX => [ 7, 8, 9, $i ], }, }, boolean => $i % 2, float => 1.1 + $i, }; } author000755000000000000 013321164704 16007 5ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/xteol.t100644000000000000 506013321164704 17114 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/xt/authoruse strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::EOL 0.19 use Test::More 0.88; use Test::EOL; my @files = ( 'lib/MaxMind/DB/Writer.pm', 'lib/MaxMind/DB/Writer/Serializer.pm', 'lib/MaxMind/DB/Writer/Tree.pm', 'lib/MaxMind/DB/Writer/Tree/Processor/VisualizeTree.pm', 'lib/MaxMind/DB/Writer/Util.pm', 't/00-report-prereqs.dd', 't/00-report-prereqs.t', 't/MaxMind/DB/Writer/Serializer-deduplication.t', 't/MaxMind/DB/Writer/Serializer-large-pointer.t', 't/MaxMind/DB/Writer/Serializer-types/array.t', 't/MaxMind/DB/Writer/Serializer-types/boolean.t', 't/MaxMind/DB/Writer/Serializer-types/bytes.t', 't/MaxMind/DB/Writer/Serializer-types/double.t', 't/MaxMind/DB/Writer/Serializer-types/end_marker.t', 't/MaxMind/DB/Writer/Serializer-types/float.t', 't/MaxMind/DB/Writer/Serializer-types/int32.t', 't/MaxMind/DB/Writer/Serializer-types/map.t', 't/MaxMind/DB/Writer/Serializer-types/pointer.t', 't/MaxMind/DB/Writer/Serializer-types/uint128.t', 't/MaxMind/DB/Writer/Serializer-types/uint16.t', 't/MaxMind/DB/Writer/Serializer-types/uint32.t', 't/MaxMind/DB/Writer/Serializer-types/uint64.t', 't/MaxMind/DB/Writer/Serializer-types/utf8_string.t', 't/MaxMind/DB/Writer/Serializer-utf8-as-bytes.t', 't/MaxMind/DB/Writer/Serializer-utf8-round-trip.t', 't/MaxMind/DB/Writer/Serializer.t', 't/MaxMind/DB/Writer/Tree-bigint.t', 't/MaxMind/DB/Writer/Tree-data-references.t', 't/MaxMind/DB/Writer/Tree-freeze-thaw.t', 't/MaxMind/DB/Writer/Tree-insert-range.t', 't/MaxMind/DB/Writer/Tree-ipv4-and-6.t', 't/MaxMind/DB/Writer/Tree-ipv6-aliases.t', 't/MaxMind/DB/Writer/Tree-iterator-large-dataset.t', 't/MaxMind/DB/Writer/Tree-iterator.t', 't/MaxMind/DB/Writer/Tree-output/0-0-0-0.t', 't/MaxMind/DB/Writer/Tree-output/basic.t', 't/MaxMind/DB/Writer/Tree-output/freeze-thaw-record-size.t', 't/MaxMind/DB/Writer/Tree-output/freeze-then-write-bug.t', 't/MaxMind/DB/Writer/Tree-output/ipv6-aliases.t', 't/MaxMind/DB/Writer/Tree-output/record-deduplication.t', 't/MaxMind/DB/Writer/Tree-output/utf8-data.t', 't/MaxMind/DB/Writer/Tree-record-collisions.t', 't/MaxMind/DB/Writer/Tree-thaw-merge.t', 't/MaxMind/DB/Writer/Tree.t', 't/MaxMind/DB/Writer/Util.t', 't/lib/Test/MaxMind/DB/Writer.pm', 't/lib/Test/MaxMind/DB/Writer/Iterator.pm', 't/lib/Test/MaxMind/DB/Writer/Serializer.pm', 't/test-data/geolite2-sample.json' ); eol_unix_ok($_, { trailing_whitespace => 1 }) foreach @files; done_testing; CONTRIBUTING.md100644000000000000 1030613321164704 16463 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003# CONTRIBUTING Thank you for considering contributing to this distribution. This file contains instructions that will help you work with the source code. Please note that if you have any questions or difficulties, you can reach the maintainer(s) through the bug queue described later in this document (preferred), or by emailing the releaser directly. You are not required to follow any of the steps in this document to submit a patch or bug report; these are recommendations, intended to help you (and help us help you faster). The distribution is managed with [Dist::Zilla](https://metacpan.org/release/Dist-Zilla). However, you can still compile and test the code with the `Makefile.PL` or `Build.PL` in the repository: perl Makefile.PL make make test or perl Build.PL ./Build ./Build test As well as: $ prove -bvr t or $ perl -Mblib t/some_test_file.t You may need to satisfy some dependencies. The easiest way to satisfy dependencies is to install the last release. This is available at https://metacpan.org/release/MaxMind-DB-Writer If you use cpanminus, you can do it without downloading the tarball first: $ cpanm --reinstall --installdeps --with-recommends MaxMind::DB::Writer Dist::Zilla is a very powerful authoring tool, but requires a number of author-specific plugins. If you would like to use it for contributing, install it from CPAN, then run one of the following commands, depending on your CPAN client: $ cpan `dzil authordeps --missing` or $ dzil authordeps --missing | cpanm There may also be additional requirements not needed by the dzil build which are needed for tests or other development: $ cpan `dzil listdeps --author --missing` or $ dzil listdeps --author --missing | cpanm Or, you can use the 'dzil stale' command to install all requirements at once: $ cpan Dist::Zilla::App::Command::stale $ cpan `dzil stale --all` or $ cpanm Dist::Zilla::App::Command::stale $ dzil stale --all | cpanm You can also do this via cpanm directly: $ cpanm --reinstall --installdeps --with-develop --with-recommends MaxMind::DB::Writer Once installed, here are some dzil commands you might try: $ dzil build $ dzil test $ dzil test --release $ dzil xtest $ dzil listdeps --json $ dzil build --notgz You can learn more about Dist::Zilla at http://dzil.org/. The code for this distribution is [hosted at GitHub](https://github.com/maxmind/MaxMind-DB-Writer-perl). You can submit code changes by forking the repository, pushing your code changes to your clone, and then submitting a pull request. Detailed instructions for doing that is available here: https://help.github.com/articles/creating-a-pull-request If you have found a bug, but do not have an accompanying patch to fix it, you can submit an issue report [via the web](https://github.com/maxmind/MaxMind-DB-Writer-perl/issues) . This is a good place to send your questions about the usage of this distribution. ## Travis All pull requests for this distribution will be automatically tested by [Travis](https://travis-ci.org/) and the build status will be reported on the pull request page. If your build fails, please take a look at the output. ## Tidyall This distribution uses [Code::TidyAll](https://metacpan.org/release/Code-TidyAll) to enforce a uniform coding style. This is tested as part of the author testing suite. You can install and run tidyall by running the following commands: $ cpanm Code::TidyAll $ tidyall -a Please run this before committing your changes and address any issues it brings up. ## Contributor Names If you send a patch or pull request, your name and email address will be included in the documentation as a contributor (using the attribution on the commit or patch), unless you specifically request for it not to be. If you wish to be listed under a different name or address, you should submit a pull request to the .mailmap file to contain the correct mapping. [Check here](https://github.com/git/git/blob/master/Documentation/mailmap.txt) for more information on git's .mailmap files. This file was generated via Dist::Zilla::Plugin::GenerateFile::FromShareDir 0.014 from a template file originating in Dist-Zilla-PluginBundle-MAXMIND-0.83. bench000755000000000000 013321164704 15131 5ustar00rootroot000000000000MaxMind-DB-Writer-0.300003memory-use100644000000000000 534613321164704 17326 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/benchuse strict; use warnings; use autodie; use v5.16; use Getopt::Long; use JSON::XS; use Math::Int128 qw( uint128 ); use MaxMind::DB::Writer::Tree; use Memory::Stats; use Net::Works::Network; use Number::Format qw( format_bytes ); my $ipv6_offset = uint128('0xA000_0000_0000_0000_0000_0000_0000_0000'); sub main { my $inserts = 10_000; my $source; GetOptions( 'inserts:i' => \$inserts, 'source:s' => \$source, ); my $stats = Memory::Stats->new(); $stats->start(); my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, database_type => 'Test', description => { en => 'Test' }, languages => ['en'], map_key_type_callback => sub { 'utf8_string' }, record_size => 24, alias_ipv6_to_ipv4 => 1, ); if ($source) { _insert_data_from_json( $tree, $inserts, $source ); } else { _insert_generated_data( $tree, $inserts ); } my $used; $stats->stop(); say 'Memory used before write: ', format_bytes( $used = $stats->get_memory_usage() ); $stats->start(); open my $fh, '>', '/dev/null'; $tree->write_tree($fh); close $fh; $stats->stop(); say 'Memory used after write: ', format_bytes( $used + $stats->get_memory_usage() ); } sub _insert_data_from_json { my $tree = shift; my $inserts = shift; my $source = shift; open my $fh, '<', $source; my $json = JSON::XS->new()->utf8(); while (<$fh>) { last if $. > $inserts; my ( $network, $record ) = @{ $json->decode($_) }; $tree->insert_network( Net::Works::Network->new_from_string( string => $network ), $record ); } } sub _insert_generated_data { my $tree = shift; my $inserts = shift; for my $int ( 1 .. $inserts ) { my $ipv4 = Net::Works::Network->new_from_integer( integer => $int, prefix_length => 128, version => 6, ); my %records; for my $i ( 1 .. 5 ) { $records{ipv4}{ 'thing' . $i } = { 'ipv4_key1-' . $i => $int, 'ipv4_key2-' . $i => { nested => "Foo $int-$i ipv4" }, }; $records{ipv6}{ 'thing' . $i } = { 'ipv6_key1-' . $i => $int, 'ipv6_key2-' . $i => { nested => "Foo $int-$i ipv6" }, }; } $tree->insert_network( $ipv4 => $records{ipv4} ); my $ipv6 = Net::Works::Network->new_from_integer( integer => $int + $ipv6_offset, mask_length => 128, ); $tree->insert_network( $ipv6 => $records{ipv6} ); } } main(); windows_mman.c100644000000000000 1272713321164704 17333 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/c/////////////////////////////////////////////////////////////////////////////// // // sys/mman.h plug-in replacement for Win32 // // Source: https://github.com/witwall/mman-win32 // // This code is distributed under the MIT License // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include "windows_mman.h" #ifdef WIN32 #ifndef FILE_MAP_EXECUTE #define FILE_MAP_EXECUTE 0x0020 #endif /* FILE_MAP_EXECUTE */ static int __map_mman_error(const DWORD err, const int deferr) { if (err == 0) { return 0; } //TODO: implement return err; } static DWORD __map_mmap_prot_page(const int prot) { DWORD protect = 0; if (prot == PROT_NONE) { return protect; } if ((prot & PROT_EXEC) != 0) { protect = ((prot & PROT_WRITE) != 0) ? PAGE_EXECUTE_READWRITE : PAGE_EXECUTE_READ; }else { protect = ((prot & PROT_WRITE) != 0) ? PAGE_READWRITE : PAGE_READONLY; } return protect; } static DWORD __map_mmap_prot_file(const int prot) { DWORD desiredAccess = 0; if (prot == PROT_NONE) { return desiredAccess; } if ((prot & PROT_READ) != 0) { desiredAccess |= FILE_MAP_READ; } if ((prot & PROT_WRITE) != 0) { desiredAccess |= FILE_MAP_WRITE; } if ((prot & PROT_EXEC) != 0) { desiredAccess |= FILE_MAP_EXECUTE; } return desiredAccess; } void * mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off) { HANDLE fm, h; void * map = MAP_FAILED; #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable: 4293) #endif const DWORD dwFileOffsetLow = (sizeof(off_t) <= sizeof(DWORD)) ? (DWORD)off : (DWORD)(off & 0xFFFFFFFFL); const DWORD dwFileOffsetHigh = (sizeof(off_t) <= sizeof(DWORD)) ? (DWORD)0 : (DWORD)((off >> 32) & 0xFFFFFFFFL); const DWORD protect = __map_mmap_prot_page(prot); const DWORD desiredAccess = __map_mmap_prot_file(prot); const off_t maxSize = off + (off_t)len; const DWORD dwMaxSizeLow = (sizeof(off_t) <= sizeof(DWORD)) ? (DWORD)maxSize : (DWORD)(maxSize & 0xFFFFFFFFL); const DWORD dwMaxSizeHigh = (sizeof(off_t) <= sizeof(DWORD)) ? (DWORD)0 : (DWORD)((maxSize >> 32) & 0xFFFFFFFFL); #ifdef _MSC_VER #pragma warning(pop) #endif errno = 0; if (len == 0 /* Unsupported flag combinations */ || (flags & MAP_FIXED) != 0 /* Usupported protection combinations */ || prot == PROT_EXEC) { errno = EINVAL; return MAP_FAILED; } h = ((flags & MAP_ANONYMOUS) == 0) ? (HANDLE)_get_osfhandle(fildes) : INVALID_HANDLE_VALUE; if ((flags & MAP_ANONYMOUS) == 0 && h == INVALID_HANDLE_VALUE) { errno = EBADF; return MAP_FAILED; } fm = CreateFileMapping(h, NULL, protect, dwMaxSizeHigh, dwMaxSizeLow, NULL); if (fm == NULL) { errno = __map_mman_error(GetLastError(), EPERM); return MAP_FAILED; } map = MapViewOfFile(fm, desiredAccess, dwFileOffsetHigh, dwFileOffsetLow, len); CloseHandle(fm); if (map == NULL) { errno = __map_mman_error(GetLastError(), EPERM); return MAP_FAILED; } return map; } int munmap(void *addr, size_t len) { if (UnmapViewOfFile(addr)) { return 0; } errno = __map_mman_error(GetLastError(), EPERM); return -1; } int mprotect(void *addr, size_t len, int prot) { DWORD newProtect = __map_mmap_prot_page(prot); DWORD oldProtect = 0; if (VirtualProtect(addr, len, newProtect, &oldProtect)) { return 0; } errno = __map_mman_error(GetLastError(), EPERM); return -1; } int msync(void *addr, size_t len, int flags) { if (FlushViewOfFile(addr, len)) { return 0; } errno = __map_mman_error(GetLastError(), EPERM); return -1; } int mlock(const void *addr, size_t len) { if (VirtualLock((LPVOID)addr, len)) { return 0; } errno = __map_mman_error(GetLastError(), EPERM); return -1; } int munlock(const void *addr, size_t len) { if (VirtualUnlock((LPVOID)addr, len)) { return 0; } errno = __map_mman_error(GetLastError(), EPERM); return -1; } #endif /* WIN32 */ windows_mman.h100644000000000000 455413321164704 17317 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/c/////////////////////////////////////////////////////////////////////////////// // // sys/mman.h plug-in replacement for Win32 // // Source: https://github.com/witwall/mman-win32 // // This code is distributed under the MIT License // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef __WINDOWS_MMAN_H__ #define __WINDOWS_MMAN_H__ #ifdef WIN32 #include #include #include <_mingw.h> #include #include #include #define PROT_NONE 0 #define PROT_READ 1 #define PROT_WRITE 2 #define PROT_EXEC 4 #define MAP_FILE 0 #define MAP_SHARED 1 #define MAP_PRIVATE 2 #define MAP_TYPE 0xf #define MAP_FIXED 0x10 #define MAP_ANONYMOUS 0x20 #define MAP_ANON MAP_ANONYMOUS #define MAP_FAILED ((void *)-1) /* Flags for msync. */ #define MS_ASYNC 1 #define MS_SYNC 2 #define MS_INVALIDATE 4 void * mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off); int munmap(void *addr, size_t len); int mprotect(void *addr, size_t len, int prot); int msync(void *addr, size_t len, int flags); int mlock(const void *addr, size_t len); int munlock(const void *addr, size_t len); #endif /* WIN32 */ #endif /* __WINDOWS_MMAN_H__ */perl_math_int64.c100644000000000000 1066713321164704 17631 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/c/* * perl_math_int64.c - This file is in the public domain * Author: Salvador Fandino , Dave Rolsky * * Generated on: 2015-03-11 11:06:11 * Math::Int64 version: 0.51 * Module::CAPIMaker version: */ #include "EXTERN.h" #include "perl.h" #include "ppport.h" #ifdef __MINGW32__ #include #endif #ifdef _MSC_VER #include typedef __int64 int64_t; typedef unsigned __int64 uint64_t; #endif /* you may need to add a typemap for int64_t here if it is not defined by default in your C header files */ HV *math_int64_c_api_hash; int math_int64_c_api_min_version; int math_int64_c_api_max_version; int64_t (*math_int64_c_api_SvI64)(pTHX_ SV*); int (*math_int64_c_api_SvI64OK)(pTHX_ SV*); uint64_t (*math_int64_c_api_SvU64)(pTHX_ SV*); int (*math_int64_c_api_SvU64OK)(pTHX_ SV*); SV * (*math_int64_c_api_newSVi64)(pTHX_ int64_t); SV * (*math_int64_c_api_newSVu64)(pTHX_ uint64_t); uint64_t (*math_int64_c_api_randU64)(pTHX); int perl_math_int64_load(int required_version) { dTHX; SV **svp; eval_pv("require Math::Int64", TRUE); if (SvTRUE(ERRSV)) return 0; math_int64_c_api_hash = get_hv("Math::Int64::C_API", 0); if (!math_int64_c_api_hash) { sv_setpv(ERRSV, "Unable to load Math::Int64 C API"); SvSETMAGIC(ERRSV); return 0; } svp = hv_fetch(math_int64_c_api_hash, "min_version", 11, 0); if (!svp) svp = hv_fetch(math_int64_c_api_hash, "version", 7, 1); if (!svp || !*svp) { sv_setpv(ERRSV, "Unable to retrieve C API version for Math::Int64"); SvSETMAGIC(ERRSV); return 0; } math_int64_c_api_min_version = SvIV(*svp); svp = hv_fetch(math_int64_c_api_hash, "max_version", 11, 0); if (!svp) svp = hv_fetch(math_int64_c_api_hash, "version", 7, 1); if (!svp || !*svp) { sv_setpv(ERRSV, "Unable to retrieve C API version for Math::Int64"); SvSETMAGIC(ERRSV); return 0; } math_int64_c_api_max_version = SvIV(*svp); if ((required_version < math_int64_c_api_min_version) || (required_version > math_int64_c_api_max_version)) { sv_setpvf(ERRSV, "Math::Int64 C API version mismatch. " "The installed module supports versions %d to %d but %d is required", math_int64_c_api_min_version, math_int64_c_api_max_version, required_version); SvSETMAGIC(ERRSV); return 0; } svp = hv_fetch(math_int64_c_api_hash, "SvI64", 5, 0); if (!svp || !*svp) { sv_setpv(ERRSV, "Unable to fetch pointer 'SvI64' C function from Math::Int64"); SvSETMAGIC(ERRSV); return 0; } math_int64_c_api_SvI64 = INT2PTR(void *, SvIV(*svp)); svp = hv_fetch(math_int64_c_api_hash, "SvI64OK", 7, 0); if (!svp || !*svp) { sv_setpv(ERRSV, "Unable to fetch pointer 'SvI64OK' C function from Math::Int64"); SvSETMAGIC(ERRSV); return 0; } math_int64_c_api_SvI64OK = INT2PTR(void *, SvIV(*svp)); svp = hv_fetch(math_int64_c_api_hash, "SvU64", 5, 0); if (!svp || !*svp) { sv_setpv(ERRSV, "Unable to fetch pointer 'SvU64' C function from Math::Int64"); SvSETMAGIC(ERRSV); return 0; } math_int64_c_api_SvU64 = INT2PTR(void *, SvIV(*svp)); svp = hv_fetch(math_int64_c_api_hash, "SvU64OK", 7, 0); if (!svp || !*svp) { sv_setpv(ERRSV, "Unable to fetch pointer 'SvU64OK' C function from Math::Int64"); SvSETMAGIC(ERRSV); return 0; } math_int64_c_api_SvU64OK = INT2PTR(void *, SvIV(*svp)); svp = hv_fetch(math_int64_c_api_hash, "newSVi64", 8, 0); if (!svp || !*svp) { sv_setpv(ERRSV, "Unable to fetch pointer 'newSVi64' C function from Math::Int64"); SvSETMAGIC(ERRSV); return 0; } math_int64_c_api_newSVi64 = INT2PTR(void *, SvIV(*svp)); svp = hv_fetch(math_int64_c_api_hash, "newSVu64", 8, 0); if (!svp || !*svp) { sv_setpv(ERRSV, "Unable to fetch pointer 'newSVu64' C function from Math::Int64"); SvSETMAGIC(ERRSV); return 0; } math_int64_c_api_newSVu64 = INT2PTR(void *, SvIV(*svp)); svp = hv_fetch(math_int64_c_api_hash, "randU64", 7, 0); if (!svp || !*svp) { sv_setpv(ERRSV, "Unable to fetch pointer 'randU64' C function from Math::Int64"); SvSETMAGIC(ERRSV); return 0; } math_int64_c_api_randU64 = INT2PTR(void *, SvIV(*svp)); return 1; } perl_math_int64.h100644000000000000 420013321164704 17600 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/c/* * perl_math_int64.h - This file is in the public domain * Author: Salvador Fandino , Dave Rolsky * Version: 2.1 * * Generated on: 2015-03-11 11:06:11 * Math::Int64 version: 0.51 * Module::CAPIMaker version: */ #if !defined (PERL_MATH_INT64_H_INCLUDED) #define PERL_MATH_INT64_H_INCLUDED #define MATH_INT64_C_API_REQUIRED_VERSION 2 #define MATH_INT64_VERSION MATH_INT64_C_API_REQUIRED_VERSION int perl_math_int64_load(int required_version); #define PERL_MATH_INT64_LOAD perl_math_int64_load(MATH_INT64_C_API_REQUIRED_VERSION) #define PERL_MATH_INT64_LOAD_OR_CROAK \ if (PERL_MATH_INT64_LOAD); \ else croak(NULL); #define MATH_INT64_BOOT PERL_MATH_INT64_LOAD_OR_CROAK extern HV *math_int64_c_api_hash; extern int math_int64_c_api_min_version; extern int math_int64_c_api_max_version; #define math_int64_capi_version math_int64_c_api_max_version #if (defined(MATH_INT64_NATIVE_IF_AVAILABLE) && (IVSIZE == 8)) #define MATH_INT64_NATIVE 1 #endif extern int64_t (*math_int64_c_api_SvI64)(pTHX_ SV*); #define SvI64(a) ((*math_int64_c_api_SvI64)(aTHX_ (a))) extern int (*math_int64_c_api_SvI64OK)(pTHX_ SV*); #define SvI64OK(a) ((*math_int64_c_api_SvI64OK)(aTHX_ (a))) extern uint64_t (*math_int64_c_api_SvU64)(pTHX_ SV*); #define SvU64(a) ((*math_int64_c_api_SvU64)(aTHX_ (a))) extern int (*math_int64_c_api_SvU64OK)(pTHX_ SV*); #define SvU64OK(a) ((*math_int64_c_api_SvU64OK)(aTHX_ (a))) extern SV * (*math_int64_c_api_newSVi64)(pTHX_ int64_t); #define newSVi64(a) ((*math_int64_c_api_newSVi64)(aTHX_ (a))) extern SV * (*math_int64_c_api_newSVu64)(pTHX_ uint64_t); #define newSVu64(a) ((*math_int64_c_api_newSVu64)(aTHX_ (a))) extern uint64_t (*math_int64_c_api_randU64)(pTHX); #define randU64() ((*math_int64_c_api_randU64)(aTHX)) #if MATH_INT64_NATIVE #undef newSVi64 #define newSVi64 newSViv #undef newSVu64 #define newSVu64 newSVuv #define sv_seti64 sv_setiv_mg #define sv_setu64 sv_setuv_mg #else #define sv_seti64(target, i64) (sv_setsv_mg(target, sv_2mortal(newSVi64(i64)))) #define sv_setu64(target, u64) (sv_setsv_mg(target, sv_2mortal(newSVu64(u64)))) #endif #endifCapture000755000000000000 013321164704 16226 5ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/incTiny.pm100644000000000000 6615513321164704 17704 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/inc/Captureuse 5.006; use strict; use warnings; package Capture::Tiny; # ABSTRACT: Capture STDOUT and STDERR from Perl, XS or external programs our $VERSION = '0.22'; # VERSION use Carp (); use Exporter (); use IO::Handle (); use File::Spec (); use File::Temp qw/tempfile tmpnam/; use Scalar::Util qw/reftype blessed/; # Get PerlIO or fake it BEGIN { local $@; eval { require PerlIO; PerlIO->can('get_layers') } or *PerlIO::get_layers = sub { return () }; } #--------------------------------------------------------------------------# # create API subroutines and export them # [do STDOUT flag, do STDERR flag, do merge flag, do tee flag] #--------------------------------------------------------------------------# my %api = ( capture => [1,1,0,0], capture_stdout => [1,0,0,0], capture_stderr => [0,1,0,0], capture_merged => [1,1,1,0], tee => [1,1,0,1], tee_stdout => [1,0,0,1], tee_stderr => [0,1,0,1], tee_merged => [1,1,1,1], ); for my $sub ( keys %api ) { my $args = join q{, }, @{$api{$sub}}; eval "sub $sub(&;@) {unshift \@_, $args; goto \\&_capture_tee;}"; ## no critic } our @ISA = qw/Exporter/; our @EXPORT_OK = keys %api; our %EXPORT_TAGS = ( 'all' => \@EXPORT_OK ); #--------------------------------------------------------------------------# # constants and fixtures #--------------------------------------------------------------------------# my $IS_WIN32 = $^O eq 'MSWin32'; ##our $DEBUG = $ENV{PERL_CAPTURE_TINY_DEBUG}; ## ##my $DEBUGFH; ##open $DEBUGFH, "> DEBUG" if $DEBUG; ## ##*_debug = $DEBUG ? sub(@) { print {$DEBUGFH} @_ } : sub(){0}; our $TIMEOUT = 30; #--------------------------------------------------------------------------# # command to tee output -- the argument is a filename that must # be opened to signal that the process is ready to receive input. # This is annoying, but seems to be the best that can be done # as a simple, portable IPC technique #--------------------------------------------------------------------------# my @cmd = ($^X, '-C0', '-e', '$SIG{HUP}=sub{exit}; ' . 'if( my $fn=shift ){ open my $fh, qq{>$fn}; print {$fh} $$; close $fh;} ' . 'my $buf; while (sysread(STDIN, $buf, 2048)) { ' . 'syswrite(STDOUT, $buf); syswrite(STDERR, $buf)}' ); #--------------------------------------------------------------------------# # filehandle manipulation #--------------------------------------------------------------------------# sub _relayer { my ($fh, $layers) = @_; # _debug("# requested layers (@{$layers}) for @{[fileno $fh]}\n"); my %seen = ( unix => 1, perlio => 1 ); # filter these out my @unique = grep { !$seen{$_}++ } @$layers; # _debug("# applying unique layers (@unique) to @{[fileno $fh]}\n"); binmode($fh, join(":", ":raw", @unique)); } sub _name { my $glob = shift; no strict 'refs'; ## no critic return *{$glob}{NAME}; } sub _open { open $_[0], $_[1] or Carp::confess "Error from open(" . join(q{, }, @_) . "): $!"; # _debug( "# open " . join( ", " , map { defined $_ ? _name($_) : 'undef' } @_ ) . " as " . fileno( $_[0] ) . "\n" ); } sub _close { # _debug( "# closing " . ( defined $_[0] ? _name($_[0]) : 'undef' ) . " on " . fileno( $_[0] ) . "\n" ); close $_[0] or Carp::confess "Error from close(" . join(q{, }, @_) . "): $!"; } my %dup; # cache this so STDIN stays fd0 my %proxy_count; sub _proxy_std { my %proxies; if ( ! defined fileno STDIN ) { $proxy_count{stdin}++; if (defined $dup{stdin}) { _open \*STDIN, "<&=" . fileno($dup{stdin}); # _debug( "# restored proxy STDIN as " . (defined fileno STDIN ? fileno STDIN : 'undef' ) . "\n" ); } else { _open \*STDIN, "<" . File::Spec->devnull; # _debug( "# proxied STDIN as " . (defined fileno STDIN ? fileno STDIN : 'undef' ) . "\n" ); _open $dup{stdin} = IO::Handle->new, "<&=STDIN"; } $proxies{stdin} = \*STDIN; binmode(STDIN, ':utf8') if $] >= 5.008; } if ( ! defined fileno STDOUT ) { $proxy_count{stdout}++; if (defined $dup{stdout}) { _open \*STDOUT, ">&=" . fileno($dup{stdout}); # _debug( "# restored proxy STDOUT as " . (defined fileno STDOUT ? fileno STDOUT : 'undef' ) . "\n" ); } else { _open \*STDOUT, ">" . File::Spec->devnull; # _debug( "# proxied STDOUT as " . (defined fileno STDOUT ? fileno STDOUT : 'undef' ) . "\n" ); _open $dup{stdout} = IO::Handle->new, ">&=STDOUT"; } $proxies{stdout} = \*STDOUT; binmode(STDOUT, ':utf8') if $] >= 5.008; } if ( ! defined fileno STDERR ) { $proxy_count{stderr}++; if (defined $dup{stderr}) { _open \*STDERR, ">&=" . fileno($dup{stderr}); # _debug( "# restored proxy STDERR as " . (defined fileno STDERR ? fileno STDERR : 'undef' ) . "\n" ); } else { _open \*STDERR, ">" . File::Spec->devnull; # _debug( "# proxied STDERR as " . (defined fileno STDERR ? fileno STDERR : 'undef' ) . "\n" ); _open $dup{stderr} = IO::Handle->new, ">&=STDERR"; } $proxies{stderr} = \*STDERR; binmode(STDERR, ':utf8') if $] >= 5.008; } return %proxies; } sub _unproxy { my (%proxies) = @_; # _debug( "# unproxying: " . join(" ", keys %proxies) . "\n" ); for my $p ( keys %proxies ) { $proxy_count{$p}--; # _debug( "# unproxied " . uc($p) . " ($proxy_count{$p} left)\n" ); if ( ! $proxy_count{$p} ) { _close $proxies{$p}; _close $dup{$p} unless $] < 5.008; # 5.6 will have already closed this as dup delete $dup{$p}; } } } sub _copy_std { my %handles; for my $h ( qw/stdout stderr stdin/ ) { next if $h eq 'stdin' && ! $IS_WIN32; # WIN32 hangs on tee without STDIN copied my $redir = $h eq 'stdin' ? "<&" : ">&"; _open $handles{$h} = IO::Handle->new(), $redir . uc($h); # ">&STDOUT" or "<&STDIN" } return \%handles; } # In some cases we open all (prior to forking) and in others we only open # the output handles (setting up redirection) sub _open_std { my ($handles) = @_; _open \*STDIN, "<&" . fileno $handles->{stdin} if defined $handles->{stdin}; _open \*STDOUT, ">&" . fileno $handles->{stdout} if defined $handles->{stdout}; _open \*STDERR, ">&" . fileno $handles->{stderr} if defined $handles->{stderr}; } #--------------------------------------------------------------------------# # private subs #--------------------------------------------------------------------------# sub _start_tee { my ($which, $stash) = @_; # $which is "stdout" or "stderr" # setup pipes $stash->{$_}{$which} = IO::Handle->new for qw/tee reader/; pipe $stash->{reader}{$which}, $stash->{tee}{$which}; # _debug( "# pipe for $which\: " . _name($stash->{tee}{$which}) . " " . fileno( $stash->{tee}{$which} ) . " => " . _name($stash->{reader}{$which}) . " " . fileno( $stash->{reader}{$which}) . "\n" ); select((select($stash->{tee}{$which}), $|=1)[0]); # autoflush # setup desired redirection for parent and child $stash->{new}{$which} = $stash->{tee}{$which}; $stash->{child}{$which} = { stdin => $stash->{reader}{$which}, stdout => $stash->{old}{$which}, stderr => $stash->{capture}{$which}, }; # flag file is used to signal the child is ready $stash->{flag_files}{$which} = scalar tmpnam(); # execute @cmd as a separate process if ( $IS_WIN32 ) { local $@; eval "use Win32API::File qw/CloseHandle GetOsFHandle SetHandleInformation fileLastError HANDLE_FLAG_INHERIT INVALID_HANDLE_VALUE/ "; # _debug( "# Win32API::File loaded\n") unless $@; my $os_fhandle = GetOsFHandle( $stash->{tee}{$which} ); # _debug( "# Couldn't get OS handle: " . fileLastError() . "\n") if ! defined $os_fhandle || $os_fhandle == INVALID_HANDLE_VALUE(); my $result = SetHandleInformation( $os_fhandle, HANDLE_FLAG_INHERIT(), 0); # _debug( $result ? "# set no-inherit flag on $which tee\n" : ("# can't disable tee handle flag inherit: " . fileLastError() . "\n")); _open_std( $stash->{child}{$which} ); $stash->{pid}{$which} = system(1, @cmd, $stash->{flag_files}{$which}); # not restoring std here as it all gets redirected again shortly anyway } else { # use fork _fork_exec( $which, $stash ); } } sub _fork_exec { my ($which, $stash) = @_; # $which is "stdout" or "stderr" my $pid = fork; if ( not defined $pid ) { Carp::confess "Couldn't fork(): $!"; } elsif ($pid == 0) { # child # _debug( "# in child process ...\n" ); untie *STDIN; untie *STDOUT; untie *STDERR; _close $stash->{tee}{$which}; # _debug( "# redirecting handles in child ...\n" ); _open_std( $stash->{child}{$which} ); # _debug( "# calling exec on command ...\n" ); exec @cmd, $stash->{flag_files}{$which}; } $stash->{pid}{$which} = $pid } my $have_usleep = eval "use Time::HiRes 'usleep'; 1"; sub _files_exist { return 1 if @_ == grep { -f } @_; Time::HiRes::usleep(1000) if $have_usleep; return 0; } sub _wait_for_tees { my ($stash) = @_; my $start = time; my @files = values %{$stash->{flag_files}}; my $timeout = defined $ENV{PERL_CAPTURE_TINY_TIMEOUT} ? $ENV{PERL_CAPTURE_TINY_TIMEOUT} : $TIMEOUT; 1 until _files_exist(@files) || ($timeout && (time - $start > $timeout)); Carp::confess "Timed out waiting for subprocesses to start" if ! _files_exist(@files); unlink $_ for @files; } sub _kill_tees { my ($stash) = @_; if ( $IS_WIN32 ) { # _debug( "# closing handles with CloseHandle\n"); CloseHandle( GetOsFHandle($_) ) for values %{ $stash->{tee} }; # _debug( "# waiting for subprocesses to finish\n"); my $start = time; 1 until wait == -1 || (time - $start > 30); } else { _close $_ for values %{ $stash->{tee} }; waitpid $_, 0 for values %{ $stash->{pid} }; } } sub _slurp { my ($name, $stash) = @_; my ($fh, $pos) = map { $stash->{$_}{$name} } qw/capture pos/; # _debug( "# slurping captured $name from " . fileno($fh) . " at pos $pos with layers: @{[PerlIO::get_layers($fh)]}\n"); seek( $fh, $pos, 0 ) or die "Couldn't seek on capture handle for $name\n"; my $text = do { local $/; scalar readline $fh }; return defined($text) ? $text : ""; } #--------------------------------------------------------------------------# # _capture_tee() -- generic main sub for capturing or teeing #--------------------------------------------------------------------------# sub _capture_tee { # _debug( "# starting _capture_tee with (@_)...\n" ); my ($do_stdout, $do_stderr, $do_merge, $do_tee, $code, @opts) = @_; my %do = ($do_stdout ? (stdout => 1) : (), $do_stderr ? (stderr => 1) : ()); Carp::confess("Custom capture options must be given as key/value pairs\n") unless @opts % 2 == 0; my $stash = { capture => { @opts } }; for ( keys %{$stash->{capture}} ) { my $fh = $stash->{capture}{$_}; Carp::confess "Custom handle for $_ must be seekable\n" unless ref($fh) eq 'GLOB' || (blessed($fh) && $fh->isa("IO::Seekable")); } # save existing filehandles and setup captures local *CT_ORIG_STDIN = *STDIN ; local *CT_ORIG_STDOUT = *STDOUT; local *CT_ORIG_STDERR = *STDERR; # find initial layers my %layers = ( stdin => [PerlIO::get_layers(\*STDIN) ], stdout => [PerlIO::get_layers(\*STDOUT, output => 1)], stderr => [PerlIO::get_layers(\*STDERR, output => 1)], ); # _debug( "# existing layers for $_\: @{$layers{$_}}\n" ) for qw/stdin stdout stderr/; # get layers from underlying glob of tied filehandles if we can # (this only works for things that work like Tie::StdHandle) $layers{stdout} = [PerlIO::get_layers(tied *STDOUT)] if tied(*STDOUT) && (reftype tied *STDOUT eq 'GLOB'); $layers{stderr} = [PerlIO::get_layers(tied *STDERR)] if tied(*STDERR) && (reftype tied *STDERR eq 'GLOB'); # _debug( "# tied object corrected layers for $_\: @{$layers{$_}}\n" ) for qw/stdin stdout stderr/; # bypass scalar filehandles and tied handles # localize scalar STDIN to get a proxy to pick up FD0, then restore later to CT_ORIG_STDIN my %localize; $localize{stdin}++, local(*STDIN) if grep { $_ eq 'scalar' } @{$layers{stdin}}; $localize{stdout}++, local(*STDOUT) if $do_stdout && grep { $_ eq 'scalar' } @{$layers{stdout}}; $localize{stderr}++, local(*STDERR) if ($do_stderr || $do_merge) && grep { $_ eq 'scalar' } @{$layers{stderr}}; $localize{stdin}++, local(*STDIN), _open( \*STDIN, "<&=0") if tied *STDIN && $] >= 5.008; $localize{stdout}++, local(*STDOUT), _open( \*STDOUT, ">&=1") if $do_stdout && tied *STDOUT && $] >= 5.008; $localize{stderr}++, local(*STDERR), _open( \*STDERR, ">&=2") if ($do_stderr || $do_merge) && tied *STDERR && $] >= 5.008; # _debug( "# localized $_\n" ) for keys %localize; # proxy any closed/localized handles so we don't use fds 0, 1 or 2 my %proxy_std = _proxy_std(); # _debug( "# proxy std: @{ [%proxy_std] }\n" ); # update layers after any proxying $layers{stdout} = [PerlIO::get_layers(\*STDOUT, output => 1)] if $proxy_std{stdout}; $layers{stderr} = [PerlIO::get_layers(\*STDERR, output => 1)] if $proxy_std{stderr}; # _debug( "# post-proxy layers for $_\: @{$layers{$_}}\n" ) for qw/stdin stdout stderr/; # store old handles and setup handles for capture $stash->{old} = _copy_std(); $stash->{new} = { %{$stash->{old}} }; # default to originals for ( keys %do ) { $stash->{new}{$_} = ($stash->{capture}{$_} ||= File::Temp->new); seek( $stash->{capture}{$_}, 0, 2 ) or die "Could not seek on capture handle for $_\n"; $stash->{pos}{$_} = tell $stash->{capture}{$_}; # _debug("# will capture $_ on " . fileno($stash->{capture}{$_})."\n" ); _start_tee( $_ => $stash ) if $do_tee; # tees may change $stash->{new} } _wait_for_tees( $stash ) if $do_tee; # finalize redirection $stash->{new}{stderr} = $stash->{new}{stdout} if $do_merge; # _debug( "# redirecting in parent ...\n" ); _open_std( $stash->{new} ); # execute user provided code my ($exit_code, $inner_error, $outer_error, @result); { local *STDIN = *CT_ORIG_STDIN if $localize{stdin}; # get original, not proxy STDIN # _debug( "# finalizing layers ...\n" ); _relayer(\*STDOUT, $layers{stdout}) if $do_stdout; _relayer(\*STDERR, $layers{stderr}) if $do_stderr; # _debug( "# running code $code ...\n" ); local $@; eval { @result = $code->(); $inner_error = $@ }; $exit_code = $?; # save this for later $outer_error = $@; # save this for later } # restore prior filehandles and shut down tees # _debug( "# restoring filehandles ...\n" ); _open_std( $stash->{old} ); _close( $_ ) for values %{$stash->{old}}; # don't leak fds # shouldn't need relayering originals, but see rt.perl.org #114404 _relayer(\*STDOUT, $layers{stdout}) if $do_stdout; _relayer(\*STDERR, $layers{stderr}) if $do_stderr; _unproxy( %proxy_std ); # _debug( "# killing tee subprocesses ...\n" ) if $do_tee; _kill_tees( $stash ) if $do_tee; # return captured output, but shortcut in void context # unless we have to echo output to tied/scalar handles; my %got; if ( defined wantarray or ($do_tee && keys %localize) ) { for ( keys %do ) { _relayer($stash->{capture}{$_}, $layers{$_}); $got{$_} = _slurp($_, $stash); # _debug("# slurped " . length($got{$_}) . " bytes from $_\n"); } print CT_ORIG_STDOUT $got{stdout} if $do_stdout && $do_tee && $localize{stdout}; print CT_ORIG_STDERR $got{stderr} if $do_stderr && $do_tee && $localize{stderr}; } $? = $exit_code; $@ = $inner_error if $inner_error; die $outer_error if $outer_error; # _debug( "# ending _capture_tee with (@_)...\n" ); return unless defined wantarray; my @return; push @return, $got{stdout} if $do_stdout; push @return, $got{stderr} if $do_stderr && ! $do_merge; push @return, @result; return wantarray ? @return : $return[0]; } 1; __END__ =pod =encoding utf-8 =head1 NAME Capture::Tiny - Capture STDOUT and STDERR from Perl, XS or external programs =head1 VERSION version 0.22 =head1 SYNOPSIS use Capture::Tiny ':all'; # capture from external command ($stdout, $stderr, $exit) = capture { system( $cmd, @args ); }; # capture from arbitrary code (Perl or external) ($stdout, $stderr, @result) = capture { # your code here }; # capture partial or merged output $stdout = capture_stdout { ... }; $stderr = capture_stderr { ... }; $merged = capture_merged { ... }; # tee output ($stdout, $stderr) = tee { # your code here }; $stdout = tee_stdout { ... }; $stderr = tee_stderr { ... }; $merged = tee_merged { ... }; =head1 DESCRIPTION Capture::Tiny provides a simple, portable way to capture almost anything sent to STDOUT or STDERR, regardless of whether it comes from Perl, from XS code or from an external program. Optionally, output can be teed so that it is captured while being passed through to the original filehandles. Yes, it even works on Windows (usually). Stop guessing which of a dozen capturing modules to use in any particular situation and just use this one. =head1 USAGE The following functions are available. None are exported by default. =head2 capture ($stdout, $stderr, @result) = capture \&code; $stdout = capture \&code; The C<<< capture >>> function takes a code reference and returns what is sent to STDOUT and STDERR as well as any return values from the code reference. In scalar context, it returns only STDOUT. If no output was received for a filehandle, it returns an empty string for that filehandle. Regardless of calling context, all output is captured -- nothing is passed to the existing filehandles. It is prototyped to take a subroutine reference as an argument. Thus, it can be called in block form: ($stdout, $stderr) = capture { # your code here ... }; Note that the coderef is evaluated in list context. If you wish to force scalar context on the return value, you must use the C<<< scalar >>> keyword. ($stdout, $stderr, $count) = capture { my @list = qw/one two three/; return scalar @list; # $count will be 3 }; Captures are normally done to an anonymous temporary filehandle. To capture via a named file (e.g. to externally monitor a long-running capture), provide custom filehandles as a trailing list of option pairs: my $out_fh = IO::File->new("out.txt", "w+"); my $err_fh = IO::File->new("out.txt", "w+"); capture { ... } stdout => $out_fh, stderr => $err_fh; The filehandles must be readEwrite and seekable. Modifying the files or filehandles during a capture operation will give unpredictable results. Existing IO layers on them may be changed by the capture. When called in void context, C<<< capture >>> saves memory and time by not reading back from the capture handles. =head2 capture_stdout ($stdout, @result) = capture_stdout \&code; $stdout = capture_stdout \&code; The C<<< capture_stdout >>> function works just like C<<< capture >>> except only STDOUT is captured. STDERR is not captured. =head2 capture_stderr ($stderr, @result) = capture_stderr \&code; $stderr = capture_stderr \&code; The C<<< capture_stderr >>> function works just like C<<< capture >>> except only STDERR is captured. STDOUT is not captured. =head2 capture_merged ($merged, @result) = capture_merged \&code; $merged = capture_merged \&code; The C<<< capture_merged >>> function works just like C<<< capture >>> except STDOUT and STDERR are merged. (Technically, STDERR is redirected to the same capturing handle as STDOUT before executing the function.) Caution: STDOUT and STDERR output in the merged result are not guaranteed to be properly ordered due to buffering. =head2 tee ($stdout, $stderr, @result) = tee \&code; $stdout = tee \&code; The C<<< tee >>> function works just like C<<< capture >>>, except that output is captured as well as passed on to the original STDOUT and STDERR. When called in void context, C<<< tee >>> saves memory and time by not reading back from the capture handles, except when the original STDOUT OR STDERR were tied or opened to a scalar handle. =head2 tee_stdout ($stdout, @result) = tee_stdout \&code; $stdout = tee_stdout \&code; The C<<< tee_stdout >>> function works just like C<<< tee >>> except only STDOUT is teed. STDERR is not teed (output goes to STDERR as usual). =head2 tee_stderr ($stderr, @result) = tee_stderr \&code; $stderr = tee_stderr \&code; The C<<< tee_stderr >>> function works just like C<<< tee >>> except only STDERR is teed. STDOUT is not teed (output goes to STDOUT as usual). =head2 tee_merged ($merged, @result) = tee_merged \&code; $merged = tee_merged \&code; The C<<< tee_merged >>> function works just like C<<< capture_merged >>> except that output is captured as well as passed on to STDOUT. Caution: STDOUT and STDERR output in the merged result are not guaranteed to be properly ordered due to buffering. =head1 LIMITATIONS =head2 Portability Portability is a goal, not a guarantee. C<<< tee >>> requires fork, except on Windows where C<<< system(1, @cmd) >>> is used instead. Not tested on any particularly esoteric platforms yet. See the L for test result by platform. =head2 PerlIO layers Capture::Tiny does it's best to preserve PerlIO layers such as ':utf8' or ':crlf' when capturing (only for Perl 5.8.1+) . Layers should be applied to STDOUT or STDERR I the call to C<<< capture >>> or C<<< tee >>>. This may not work for tied filehandles (see below). =head2 Modifying filehandles before capturing Generally speaking, you should do little or no manipulation of the standard IO filehandles prior to using Capture::Tiny. In particular, closing, reopening, localizing or tying standard filehandles prior to capture may cause a variety of unexpected, undesirable andEor unreliable behaviors, as described below. Capture::Tiny does its best to compensate for these situations, but the results may not be what you desire. B Capture::Tiny will work even if STDIN, STDOUT or STDERR have been previously closed. However, since they will be reopened to capture or tee output, any code within the captured block that depends on finding them closed will, of course, not find them to be closed. If they started closed, Capture::Tiny will close them again when the capture block finishes. Note that this reopening will happen even for STDIN or a filehandle not being captured to ensure that the filehandle used for capture is not opened to file descriptor 0, as this causes problems on various platforms. Prior to Perl 5.12, closed STDIN combined with PERL_UNICODE=D leaks filehandles and also breaks tee() for undiagnosed reasons. So don't do that. B If code localizes any of Perl's standard filehandles before capturing, the capture will affect the localized filehandles and not the original ones. External system calls are not affected by localizing a filehandle in Perl and will continue to send output to the original filehandles (which will thus not be captured). B If STDOUT or STDERR are reopened to scalar filehandles prior to the call to C<<< capture >>> or C<<< tee >>>, then Capture::Tiny will override the output filehandle for the duration of the C<<< capture >>> or C<<< tee >>> call and then, for C<<< tee >>>, send captured output to the output filehandle after the capture is complete. (Requires Perl 5.8) Capture::Tiny attempts to preserve the semantics of STDIN opened to a scalar reference, but note that external processes will not be able to read from such a handle. Capture::Tiny tries to ensure that external processes will read from the null device instead, but this is not guaranteed. B If STDOUT or STDERR are tied prior to the call to C<<< capture >>> or C<<< tee >>>, then Capture::Tiny will attempt to override the tie for the duration of the C<<< capture >>> or C<<< tee >>> call and then send captured output to the tied filehandle after the capture is complete. (Requires Perl 5.8) Capture::Tiny may not succeed resending UTF-8 encoded data to a tied STDOUT or STDERR filehandle. Characters may appear as bytes. If the tied filehandle is based on L, then Capture::Tiny will attempt to determine appropriate layers like C<<< :utf8 >>> from the underlying filehandle and do the right thing. B Capture::Tiny attempts to preserve the semantics of tied STDIN, but this requires Perl 5.8 and is not entirely predictable. External processes will not be able to read from such a handle. Unless having STDIN tied is crucial, it may be safest to localize STDIN when capturing: my ($out, $err) = do { local *STDIN; capture { ... } }; =head2 Modifying filehandles during a capture Attempting to modify STDIN, STDOUT or STDERR I C<<< capture >>> or C<<< tee >>> is almost certainly going to cause problems. Don't do that. =head2 No support for Perl 5.8.0 It's just too buggy when it comes to layers and UTF-8. Perl 5.8.1 or later is recommended. =head2 Limited support for Perl 5.6 Perl 5.6 predates PerlIO. UTF-8 data may not be captured correctly. =head1 ENVIRONMENT =head2 PERL_CAPTURE_TINY_TIMEOUT Capture::Tiny uses subprocesses for C<<< tee >>>. By default, Capture::Tiny will timeout with an error if the subprocesses are not ready to receive data within 30 seconds (or whatever is the value of C<<< $Capture::Tiny::TIMEOUT >>>). An alternate timeout may be specified by setting the C<<< PERL_CAPTURE_TINY_TIMEOUT >>> environment variable. Setting it to zero will disable timeouts. =head1 SEE ALSO This module was, inspired by L, which provides similar functionality without the ability to tee output and with more complicated code and API. L does not handle layers or most of the unusual cases described in the L section and I no longer recommend it. There are many other CPAN modules that provide some sort of output capture, albeit with various limitations that make them appropriate only in particular circumstances. I'm probably missing some. The long list is provided to show why I felt Capture::Tiny was necessary. =over =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =back =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan =head1 SUPPORT =head2 Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at L. You will be notified automatically of any progress on your issue. =head2 Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. L git clone git://github.com/dagolden/capture-tiny.git =head1 AUTHOR David Golden =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2009 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 =cut no-tabs.t100644000000000000 502613321164704 17702 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/xt/authoruse strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::NoTabs 0.15 use Test::More 0.88; use Test::NoTabs; my @files = ( 'lib/MaxMind/DB/Writer.pm', 'lib/MaxMind/DB/Writer/Serializer.pm', 'lib/MaxMind/DB/Writer/Tree.pm', 'lib/MaxMind/DB/Writer/Tree/Processor/VisualizeTree.pm', 'lib/MaxMind/DB/Writer/Util.pm', 't/00-report-prereqs.dd', 't/00-report-prereqs.t', 't/MaxMind/DB/Writer/Serializer-deduplication.t', 't/MaxMind/DB/Writer/Serializer-large-pointer.t', 't/MaxMind/DB/Writer/Serializer-types/array.t', 't/MaxMind/DB/Writer/Serializer-types/boolean.t', 't/MaxMind/DB/Writer/Serializer-types/bytes.t', 't/MaxMind/DB/Writer/Serializer-types/double.t', 't/MaxMind/DB/Writer/Serializer-types/end_marker.t', 't/MaxMind/DB/Writer/Serializer-types/float.t', 't/MaxMind/DB/Writer/Serializer-types/int32.t', 't/MaxMind/DB/Writer/Serializer-types/map.t', 't/MaxMind/DB/Writer/Serializer-types/pointer.t', 't/MaxMind/DB/Writer/Serializer-types/uint128.t', 't/MaxMind/DB/Writer/Serializer-types/uint16.t', 't/MaxMind/DB/Writer/Serializer-types/uint32.t', 't/MaxMind/DB/Writer/Serializer-types/uint64.t', 't/MaxMind/DB/Writer/Serializer-types/utf8_string.t', 't/MaxMind/DB/Writer/Serializer-utf8-as-bytes.t', 't/MaxMind/DB/Writer/Serializer-utf8-round-trip.t', 't/MaxMind/DB/Writer/Serializer.t', 't/MaxMind/DB/Writer/Tree-bigint.t', 't/MaxMind/DB/Writer/Tree-data-references.t', 't/MaxMind/DB/Writer/Tree-freeze-thaw.t', 't/MaxMind/DB/Writer/Tree-insert-range.t', 't/MaxMind/DB/Writer/Tree-ipv4-and-6.t', 't/MaxMind/DB/Writer/Tree-ipv6-aliases.t', 't/MaxMind/DB/Writer/Tree-iterator-large-dataset.t', 't/MaxMind/DB/Writer/Tree-iterator.t', 't/MaxMind/DB/Writer/Tree-output/0-0-0-0.t', 't/MaxMind/DB/Writer/Tree-output/basic.t', 't/MaxMind/DB/Writer/Tree-output/freeze-thaw-record-size.t', 't/MaxMind/DB/Writer/Tree-output/freeze-then-write-bug.t', 't/MaxMind/DB/Writer/Tree-output/ipv6-aliases.t', 't/MaxMind/DB/Writer/Tree-output/record-deduplication.t', 't/MaxMind/DB/Writer/Tree-output/utf8-data.t', 't/MaxMind/DB/Writer/Tree-record-collisions.t', 't/MaxMind/DB/Writer/Tree-thaw-merge.t', 't/MaxMind/DB/Writer/Tree.t', 't/MaxMind/DB/Writer/Util.t', 't/lib/Test/MaxMind/DB/Writer.pm', 't/lib/Test/MaxMind/DB/Writer/Iterator.pm', 't/lib/Test/MaxMind/DB/Writer/Serializer.pm', 't/test-data/geolite2-sample.json' ); notabs_ok($_) foreach @files; done_testing; perl_math_int128.c100644000000000000 722013321164704 17661 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/c/* * perl_math_int128.c - This file is in the public domain * Author: Salvador Fandino , Dave Rolsky * * Generated on: 2015-03-11 11:04:45 * Math::Int128 version: 0.21 */ #include "EXTERN.h" #include "perl.h" #include "ppport.h" #if ((__GNUC__ == 4) && (__GNUC_MINOR__ < 6)) /* workaroung for gcc 4.4/4.5 - see http://gcc.gnu.org/gcc-4.4/changes.html */ typedef int int128_t __attribute__ ((__mode__ (TI))); typedef unsigned int uint128_t __attribute__ ((__mode__ (TI))); #else typedef __int128 int128_t; typedef unsigned __int128 uint128_t; #endif HV *math_int128_c_api_hash = NULL; int math_int128_c_api_min_version = 0; int math_int128_c_api_max_version = 0; int128_t (*math_int128_c_api_SvI128)(pTHX_ SV *sv) = NULL; int (*math_int128_c_api_SvI128OK)(pTHX_ SV*) = NULL; int128_t (*math_int128_c_api_SvU128)(pTHX_ SV *sv) = NULL; int (*math_int128_c_api_SvU128OK)(pTHX_ SV*) = NULL; SV * (*math_int128_c_api_newSVi128)(pTHX_ int128_t i128) = NULL; SV * (*math_int128_c_api_newSVu128)(pTHX_ uint128_t u128) = NULL; int perl_math_int128_load(int required_version) { dTHX; SV **svp; eval_pv("require Math::Int128", TRUE); if (SvTRUE(ERRSV)) return 0; math_int128_c_api_hash = get_hv("Math::Int128::C_API", 0); if (!math_int128_c_api_hash) { sv_setpv_mg(ERRSV, "Unable to load Math::Int128 C API"); return 0; } math_int128_c_api_min_version = SvIV(*hv_fetch(math_int128_c_api_hash, "min_version", 11, 1)); math_int128_c_api_max_version = SvIV(*hv_fetch(math_int128_c_api_hash, "max_version", 11, 1)); if ((required_version < math_int128_c_api_min_version) || (required_version > math_int128_c_api_max_version)) { sv_setpvf_mg(ERRSV, "Math::Int128 C API version mismatch. " "The installed module supports versions %d to %d but %d is required", math_int128_c_api_min_version, math_int128_c_api_max_version, required_version); return 0; } svp = hv_fetch(math_int128_c_api_hash, "SvI128", 6, 0); if (!svp || !*svp) { sv_setpv_mg(ERRSV, "Unable to fetch pointer 'SvI128' C function from Math::Int128"); return 0; } math_int128_c_api_SvI128 = INT2PTR(void *, SvIV(*svp)); svp = hv_fetch(math_int128_c_api_hash, "SvI128OK", 8, 0); if (!svp || !*svp) { sv_setpv_mg(ERRSV, "Unable to fetch pointer 'SvI128OK' C function from Math::Int128"); return 0; } math_int128_c_api_SvI128OK = INT2PTR(void *, SvIV(*svp)); svp = hv_fetch(math_int128_c_api_hash, "SvU128", 6, 0); if (!svp || !*svp) { sv_setpv_mg(ERRSV, "Unable to fetch pointer 'SvU128' C function from Math::Int128"); return 0; } math_int128_c_api_SvU128 = INT2PTR(void *, SvIV(*svp)); svp = hv_fetch(math_int128_c_api_hash, "SvU128OK", 8, 0); if (!svp || !*svp) { sv_setpv_mg(ERRSV, "Unable to fetch pointer 'SvU128OK' C function from Math::Int128"); return 0; } math_int128_c_api_SvU128OK = INT2PTR(void *, SvIV(*svp)); svp = hv_fetch(math_int128_c_api_hash, "newSVi128", 9, 0); if (!svp || !*svp) { sv_setpv_mg(ERRSV, "Unable to fetch pointer 'newSVi128' C function from Math::Int128"); return 0; } math_int128_c_api_newSVi128 = INT2PTR(void *, SvIV(*svp)); svp = hv_fetch(math_int128_c_api_hash, "newSVu128", 9, 0); if (!svp || !*svp) { sv_setpv_mg(ERRSV, "Unable to fetch pointer 'newSVu128' C function from Math::Int128"); return 0; } math_int128_c_api_newSVu128 = INT2PTR(void *, SvIV(*svp)); return 1; } perl_math_int128.h100644000000000000 267413321164704 17676 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/c/* * perl_math_int128.h - This file is in the public domain * Author: Salvador Fandino , Dave Rolsky * * Generated on: 2015-03-11 11:04:45 * Math::Int128 version: 0.21 */ #if !defined (PERL_MATH_INT128_H_INCLUDED) #define PERL_MATH_INT128_H_INCLUDED #define MATH_INT128_C_API_REQUIRED_VERSION 1 int perl_math_int128_load(int required_version); #define PERL_MATH_INT128_LOAD perl_math_int128_load(MATH_INT128_C_API_REQUIRED_VERSION) #define PERL_MATH_INT128_LOAD_OR_CROAK \ if (PERL_MATH_INT128_LOAD); \ else croak(NULL); extern HV *math_int128_c_api_hash; extern int math_int128_c_api_min_version; extern int math_int128_c_api_max_version; extern int128_t (*math_int128_c_api_SvI128)(pTHX_ SV *sv); #define SvI128(a) ((*math_int128_c_api_SvI128)(aTHX_ (a))) extern int (*math_int128_c_api_SvI128OK)(pTHX_ SV*); #define SvI128OK(a) ((*math_int128_c_api_SvI128OK)(aTHX_ (a))) extern int128_t (*math_int128_c_api_SvU128)(pTHX_ SV *sv); #define SvU128(a) ((*math_int128_c_api_SvU128)(aTHX_ (a))) extern int (*math_int128_c_api_SvU128OK)(pTHX_ SV*); #define SvU128OK(a) ((*math_int128_c_api_SvU128OK)(aTHX_ (a))) extern SV * (*math_int128_c_api_newSVi128)(pTHX_ int128_t i128); #define newSVi128(a) ((*math_int128_c_api_newSVi128)(aTHX_ (a))) extern SV * (*math_int128_c_api_newSVu128)(pTHX_ uint128_t u128); #define newSVu128(a) ((*math_int128_c_api_newSVu128)(aTHX_ (a))) #endif inc000755000000000000 013321164704 14623 5ustar00rootroot000000000000MaxMind-DB-Writer-0.300003MyModuleBuild.pm100644000000000000 712013321164704 20034 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/inc## no critic (NamingConventions::Capitalization) package inc::MyModuleBuild; use strict; use warnings; use namespace::autoclean; use Dist::Zilla::File::InMemory; use Moose; extends 'Dist::Zilla::Plugin::ModuleBuild'; my $template = <<'EOT'; use strict; use warnings; use lib 'inc'; use Config qw( %Config ); use Config::AutoConf; use Module::Build; if ( $^O =~ /Win32/ ) { die 'This distribution does not work on Windows platforms.' . " See the documentation for details.\n"; } my {{ $module_build_args }} my $mb = Module::Build->new( %module_build_args, c_source => 'c', ); $mb->extra_compiler_flags( _cc_flags($mb) ); $mb->create_build_script(); sub _cc_flags { my $mb = shift; my %unique = map { $_ => 1 } qw( -std=c99 -fms-extensions -Wall -g ), @{ $mb->extra_compiler_flags || [] }, _int64_define(), _int128_define(); return keys %unique; } sub _int64_define { my $autoconf = Config::AutoConf->new; return unless $autoconf->check_default_headers(); return '-DINT64_T' if $autoconf->check_type('int64_t'); return '-D__INT64' if $autoconf->check_type('__int64'); return '-DINT64_DI' if $autoconf->check_type('int __attribute__ ((__mode__ (DI)))'); warn <<'EOF'; It looks like your compiler doesn't support a 64-bit integer type (one of "int64_t" or "__int64"). One of these types is necessary to compile the Math::Int64 module. EOF exit 1; } sub _int128_define { my $autoconf = Config::AutoConf->new; return unless $autoconf->check_default_headers(); return '-D__INT128' if _check_type( $autoconf, '__int128' ); return '-DINT128_TI' if _check_type( $autoconf, 'int __attribute__ ((__mode__ (TI)))' ); warn <<'EOF'; It looks like your compiler doesn't support a 128-bit integer type (one of "int __attribute__ ((__mode__ (TI)))" or "__int128"). One of these types is necessary to compile the Math::Int128 module. EOF exit 1; } # This more complex check is needed in order to ferret out bugs with clang on # i386 platforms. See http://llvm.org/bugs/show_bug.cgi?id=15834 for the bug # report. This appears to be sub _check_type { my $autoconf = shift; my $type = shift; my $uint64_type = $autoconf->check_type('uint64_t') ? 'uint64_t' : $autoconf->check_type( 'unsigned int __attribute__ ((__mode__ (DI)))') ? 'unsigned int __attribute__ ((__mode__ (DI)))' : return 0; my $cache_name = $autoconf->_cache_type_name( 'type', $type ); my $check_sub = sub { my $prologue = $autoconf->_default_includes(); $prologue .= $type =~ /__mode__/ ? "typedef unsigned uint128_t __attribute__((__mode__(TI)));\n" : "typedef unsigned __int128 uint128_t;\n"; # The rand() calls are there because if we just use constants than the # compiler can optimize most of this code away. my $body = <<"EOF"; $uint64_type a = (($uint64_type)rand()) * rand(); $uint64_type b = (($uint64_type)rand()) << 24; uint128_t c = ((uint128_t)a) * b; return c > rand(); EOF my $conftest = $autoconf->lang_build_program( $prologue, $body ); return $autoconf->compile_if_else($conftest); }; return $autoconf->check_cached( $cache_name, "for $type", $check_sub ); } EOT sub gather_files { my ($self) = @_; my $file = Dist::Zilla::File::InMemory->new( { name => 'Build.PL', content => $template, # template evaluated later } ); $self->add_file($file); return; } __PACKAGE__->meta()->make_immutable(); 1; mojibake.t100644000000000000 15113321164704 20072 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/xt/author#!perl use strict; use warnings qw(all); use Test::More; use Test::Mojibake; all_files_encoding_ok(); synopsis.t100644000000000000 6013321164704 20157 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/xt/author#!perl use Test::Synopsis; all_synopsis_ok(); pod-spell.t100644000000000000 121713321164704 20234 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/xt/authoruse strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::PodSpelling 2.007005 use Test::Spelling 0.12; use Pod::Wordlist; add_stopwords(); all_pod_files_spelling_ok( qw( bin lib ) ); __DATA__ Alders Alders' Bieron CIDR Chelluri DB Dave Eilam Eilam's Florian Fowler GeoIP Greg Ilya Inc Jan MAXMIND MAXMIND's MMDB Mark Mather MaxMind MaxMind's Melamed Narsimham Olaf Oschwald Oschwald's PayPal Processor Ragwitz Rolsky Rolsky's Serializer Storey TW Teredo Thomas Tree Util VisualizeTree William Writer docs drolsky en goschwald ilya77 jbieron lib mfowler nchelluri oalders rafl routable tjmather toplevel uint wstorey zh t000755000000000000 013321164704 14315 5ustar00rootroot000000000000MaxMind-DB-Writer-0.30000300-report-prereqs.t100644000000000000 1342613321164704 20077 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t#!perl use strict; use warnings; # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.027 use Test::More tests => 1; use ExtUtils::MakeMaker; use File::Spec; # from $version::LAX my $lax_version_re = qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )? | (?:\.[0-9]+) (?:_[0-9]+)? ) | (?: v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )? | (?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)? ) )/x; # hide optional CPAN::Meta modules from prereq scanner # and check if they are available my $cpan_meta = "CPAN::Meta"; my $cpan_meta_pre = "CPAN::Meta::Prereqs"; my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic # Verify requirements? my $DO_VERIFY_PREREQS = 1; sub _max { my $max = shift; $max = ( $_ > $max ) ? $_ : $max for @_; return $max; } sub _merge_prereqs { my ($collector, $prereqs) = @_; # CPAN::Meta::Prereqs object if (ref $collector eq $cpan_meta_pre) { return $collector->with_merged_prereqs( CPAN::Meta::Prereqs->new( $prereqs ) ); } # Raw hashrefs for my $phase ( keys %$prereqs ) { for my $type ( keys %{ $prereqs->{$phase} } ) { for my $module ( keys %{ $prereqs->{$phase}{$type} } ) { $collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module}; } } } return $collector; } my @include = qw( ); my @exclude = qw( ); # Add static prereqs to the included modules list my $static_prereqs = do './t/00-report-prereqs.dd'; # Merge all prereqs (either with ::Prereqs or a hashref) my $full_prereqs = _merge_prereqs( ( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ), $static_prereqs ); # Add dynamic prereqs to the included modules list (if we can) my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; my $cpan_meta_error; if ( $source && $HAS_CPAN_META && (my $meta = eval { CPAN::Meta->load_file($source) } ) ) { $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs); } else { $cpan_meta_error = $@; # capture error from CPAN::Meta->load_file($source) $source = 'static metadata'; } my @full_reports; my @dep_errors; my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs; # Add static includes into a fake section for my $mod (@include) { $req_hash->{other}{modules}{$mod} = 0; } for my $phase ( qw(configure build test runtime develop other) ) { next unless $req_hash->{$phase}; next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING}); for my $type ( qw(requires recommends suggests conflicts modules) ) { next unless $req_hash->{$phase}{$type}; my $title = ucfirst($phase).' '.ucfirst($type); my @reports = [qw/Module Want Have/]; for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) { next if $mod eq 'perl'; next if grep { $_ eq $mod } @exclude; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC; my $want = $req_hash->{$phase}{$type}{$mod}; $want = "undef" unless defined $want; $want = "any" if !$want && $want == 0; my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required"; if ($prefix) { my $have = MM->parse_version( File::Spec->catfile($prefix, $file) ); $have = "undef" unless defined $have; push @reports, [$mod, $want, $have]; if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) { if ( $have !~ /\A$lax_version_re\z/ ) { push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)"; } elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) { push @dep_errors, "$mod version '$have' is not in required range '$want'"; } } } else { push @reports, [$mod, $want, "missing"]; if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) { push @dep_errors, "$mod is not installed ($req_string)"; } } } if ( @reports ) { push @full_reports, "=== $title ===\n\n"; my $ml = _max( map { length $_->[0] } @reports ); my $wl = _max( map { length $_->[1] } @reports ); my $hl = _max( map { length $_->[2] } @reports ); if ($type eq 'modules') { splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports; } else { splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports; } push @full_reports, "\n"; } } } if ( @full_reports ) { diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports; } if ( $cpan_meta_error || @dep_errors ) { diag "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n"; } if ( $cpan_meta_error ) { my ($orig_source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; diag "\nCPAN::Meta->load_file('$orig_source') failed with: $cpan_meta_error\n"; } if ( @dep_errors ) { diag join("\n", "\nThe following REQUIRED prerequisites were not satisfied:\n", @dep_errors, "\n" ); } pass; # vim: ts=4 sts=4 sw=4 et: Config000755000000000000 013321164704 16030 5ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/incAutoConf.pm100644000000000000 15030413321164704 20307 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/inc/Configpackage Config::AutoConf; use ExtUtils::CBuilder; use 5.008002; use Config; use Carp qw/croak/; use File::Temp qw/tempfile/; use File::Basename; use File::Spec; use Capture::Tiny qw/capture/; use Scalar::Util qw/looks_like_number/; # in core since 5.7.3 use base 'Exporter'; our @EXPORT = ('$LIBEXT', '$EXEEXT'); use warnings; use strict; # XXX detect HP-UX / HPPA our $LIBEXT = (defined $Config{dlext}) ? ("." . $Config{dlext}) : ($^O =~ /darwin/i) ? ".dylib" : ( ($^O =~ /mswin32/i) ? ".dll" : ".so" ); our $EXEEXT = ($^O =~ /mswin32/i) ? ".exe" : ""; =encoding UTF-8 =head1 NAME Config::AutoConf - A module to implement some of AutoConf macros in pure perl. =cut our $VERSION = '0.22'; =head1 ABSTRACT With this module I pretend to simulate some of the tasks AutoConf macros do. To detect a command, to detect a library, etc. =head1 SYNOPSIS use Config::AutoConf; Config::AutoConf->check_prog("agrep"); my $grep = Config::AutoConf->check_progs("agrep", "egrep", "grep"); Config::AutoConf->check_header("ncurses.h"); my $curses = Config::AutoConf->check_headers("ncurses.h","curses.h"); Config::AutoConf->check_prog_awk; Config::AutoConf->check_prog_egrep; Config::AutoConf->check_cc(); Config::AutoConf->check_lib("ncurses", "tgoto"); Config::AutoConf->check_file("/etc/passwd"); # -f && -r =head1 FUNCTIONS =cut my $glob_instance; =head2 new This function instantiates a new instance of Config::AutoConf, eg. to configure child components. =cut sub new { my $class = shift; ref $class and $class = ref $class; my %args = @_; my %instance = ( msg_prefix => 'configure: ', lang => "C", lang_stack => [], lang_supported => { "C" => "ExtUtils::CBuilder", }, cache => {}, defines => {}, extra_libs => [], extra_lib_dirs => [], extra_include_dirs => [], extra_preprocess_flags => [], extra_compile_flags => { "C" => [], }, extra_link_flags => [], logfile => "config.log", %args ); my $self = bless( \%instance, $class ); return $self; } =head2 check_file This function checks if a file exists in the system and is readable by the user. Returns a boolean. You can use '-f $file && -r $file' so you don't need to use a function call. =cut sub check_file { my $self = shift; my $file = shift; return (-f $file && -r $file); } =head2 check_files This function checks if a set of files exist in the system and are readable by the user. Returns a boolean. =cut sub check_files { my $self = shift; for (@_) { return 0 unless check_file($self, $_) } return 1; } =head2 check_prog This function checks for a program with the supplied name. In success returns the full path for the executable; =cut sub check_prog { my $self = shift; # sanitize ac_prog my $ac_prog = _sanitize(shift()); my $PATH = $ENV{PATH}; my $p; my $ext = ""; $ext = ".exe" if $^O =~ /mswin/i; for $p (split /$Config{path_sep}/,$PATH) { my $cmd = File::Spec->catfile($p,$ac_prog.$ext); return $cmd if -x $cmd; } return undef; } =head2 check_progs This function takes a list of program names. Returns the full path for the first found on the system. Returns undef if none was found. =cut sub check_progs { my $self = shift; my @progs = @_; for (@progs) { my $ans = check_prog($self, $_); return $ans if $ans; } return undef; } =head2 check_prog_yacc From the autoconf documentation, If `bison' is found, set [...] `bison -y'. Otherwise, if `byacc' is found, set [...] `byacc'. Otherwise set [...] `yacc'. Returns the full path, if found. =cut sub check_prog_yacc { my $self = shift; my $binary = check_progs(qw/$self bison byacc yacc/); $binary .= " -y" if ($binary =~ /bison$/); return $binary; } =head2 check_prog_awk From the autoconf documentation, Check for `gawk', `mawk', `nawk', and `awk', in that order, and set output [...] to the first one that is found. It tries `gawk' first because that is reported to be the best implementation. Note that it returns the full path, if found. =cut sub check_prog_awk { my $self = shift; return check_progs(qw/$self gawk mawk nawk awk/); } =head2 check_prog_egrep From the autoconf documentation, Check for `grep -E' and `egrep', in that order, and [...] output [...] the first one that is found. Note that it returns the full path, if found. =cut sub check_prog_egrep { my $self = shift; my $grep; if ($grep = check_prog($self,"grep")) { my $ans = `echo a | ($grep -E '(a|b)') 2>/dev/null`; return "$grep -E" if $ans eq "a\n"; } if ($grep = check_prog($self, "egrep")) { return $grep; } return undef; } =head2 check_cc This function checks if you have a running C compiler. =cut sub check_cc { ExtUtils::CBuilder->new(quiet => 1)->have_compiler; } =head2 msg_checking Prints "Checking @_ ..." =cut sub msg_checking { my $self = shift->_get_instance(); $self->{quiet} or print "Checking " . join(" ", @_) . "... "; $self->_add2log( "Checking " . join( " ", @_, "..." ) ); return; } =head2 msg_result Prints result \n =cut sub msg_result { my $self = shift->_get_instance(); $self->{quiet} or print join( " ", map { looks_like_number( $_ ) ? ( $_ == 0 ? "no" : ( $_ == 1 ? "yes" : $_ ) ) : $_ } @_ ), "\n"; return; } =head2 msg_notice Prints "configure: " @_ to stdout =cut sub msg_notice { my $self = shift->_get_instance(); $self->{quiet} or print $self->{msg_prefix} . join( " ", @_ ) . "\n"; return; } =head2 msg_warn Prints "configure: " @_ to stderr =cut sub msg_warn { my $self = shift->_get_instance(); $self->{quiet} or print STDERR $self->{msg_prefix} . join( " ", @_ ) . "\n"; return; } =head2 msg_error Prints "configure: " @_ to stderr and exits with exit code 0 (tells toolchain to stop here and report unsupported environment) =cut sub msg_error { my $self = shift->_get_instance(); $self->{quiet} or print STDERR $self->{msg_prefix} . join( " ", @_ ) . "\n"; exit(0); # #toolchain agreement: prevents configure stage to finish } =head2 msg_failure Prints "configure: " @_ to stderr and exits with exit code 0 (tells toolchain to stop here and report unsupported environment). Additional details are provides in config.log (probably more information in a later stage). =cut sub msg_failure { my $self = shift->_get_instance(); $self->{quiet} or print STDERR $self->{msg_prefix} . join( " ", @_ ) . "\n"; exit(0); # #toolchain agreement: prevents configure stage to finish } =head2 define_var( $name, $value [, $comment ] ) Defines a check variable for later use in further checks or code to compile. =cut sub define_var { my $self = shift->_get_instance(); my ($name, $value, $comment) = @_; defined( $name ) or croak( "Need a name to add a define" ); $self->{defines}->{$name} = [ $value, $comment ]; return; } =head2 write_config_h( [$target] ) Writes the defined constants into given target: Config::AutoConf->write_config_h( "config.h" ); =cut sub write_config_h { my $self = shift->_get_instance(); my $tgt; defined( $_[0] ) ? ( ref( $_[0] ) ? $tgt = $_[0] : open( $tgt, ">", $_[0] ) ) : open( $tgt, ">", "config.h" ); my $conf_h = <<'EOC'; /** * Generated from Config::AutoConf * * Do not edit this file, all modifications will be lost, * modify Makefile.PL or Build.PL instead. * * Inspired by GNU AutoConf. * * (c) 2011 Alberto Simoes & Jens Rehsack */ #ifndef __CONFIG_H__ EOC while( my ($defname, $defcnt) = each( %{ $self->{defines} } ) ) { if( $defcnt->[0] ) { defined $defcnt->[1] and $conf_h .= "/* " . $defcnt->[1] . " */\n"; $conf_h .= join( " ", "#define", $defname, $defcnt->[0] ) . "\n"; } else { defined $defcnt->[1] and $conf_h .= "/* " . $defcnt->[1] . " */\n"; $conf_h .= "/* " . join( " ", "#undef", $defname ) . " */\n\n"; } } $conf_h .= "#endif /* ?__CONFIG_H__ */\n"; print {$tgt} $conf_h; return; } =head2 push_lang(lang [, implementor ]) Puts the current used language on the stack and uses specified language for subsequent operations until ending pop_lang call. =cut sub push_lang { my $self = shift->_get_instance(); push @{$self->{lang_stack}}, [ $self->{lang} ]; return $self->_set_language( @_ ); } =head2 pop_lang([ lang ]) Pops the currently used language from the stack and restores previously used language. If I specified, it's asserted that the current used language equals to specified language (helps finding control flow bugs). =cut sub pop_lang { my $self = shift->_get_instance(); scalar( @{$self->{lang_stack}} ) > 0 or croak( "Language stack empty" ); defined( $_[0] ) and $self->{lang} ne $_[0] and croak( "pop_lang( $_[0] ) doesn't match language in use (" . $self->{lang} . ")" ); return $self->_set_language( @{ pop @{ $self->{lang} } } ); } =head2 lang_call( [prologue], function ) Builds program which simply calls given function. When given, prologue is prepended otherwise, the default includes are used. =cut sub lang_call { my $self = shift->_get_instance(); my ($prologue, $function) = @_; defined( $prologue ) or $prologue = $self->_default_includes(); $prologue .= <<"_ACEOF"; /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" { #endif char $function (); #ifdef __cplusplus } #endif _ACEOF my $body = "return $function ();"; $body = $self->_build_main( $body ); my $conftest = $self->_fill_defines(); $conftest .= "\n$prologue\n"; $conftest .= "\n$body\n"; return $conftest; } =head2 lang_build_program( prologue, body ) Builds program for current chosen language. If no prologue is given (I), the default headers are used. If body is missing, default body is used. Typical call of Config::AutoConf->lang_build_program( "const char hw[] = \"Hello, World\\n\";", "fputs (hw, stdout);" ) will create const char hw[] = "Hello, World\n"; /* Override any gcc2 internal prototype to avoid an error. */ #ifdef __cplusplus extern "C" { #endif int main (int argc, char **argv) { (void)argc; (void)argv; fputs (hw, stdout);; return 0; } #ifdef __cplusplus } #endif =cut sub lang_build_program { my $self = shift->_get_instance(); my ($prologue, $body) = @_; defined( $prologue ) or $prologue = $self->_default_includes(); defined( $body ) or $body = ""; $body = $self->_build_main( $body ); my $conftest = $self->_fill_defines(); $conftest .= "\n$prologue\n"; $conftest .= "\n$body\n"; return $conftest; } =head2 lang_build_bool_test (prologue, test, [@decls]) Builds a static test which will fail to compile when test evaluates to false. If C<@decls> is given, it's prepended before the test code at the variable definition place. =cut sub lang_build_bool_test { my $self = shift->_get_instance(); my ($prologue, $test, @decls) = @_; defined( $test ) or $test = "1"; my $test_code = <lang_build_program( $prologue, $test_code ); } =head2 push_includes Adds given list of directories to preprocessor/compiler invocation. This is not proved to allow adding directories which might be created during the build. =cut sub push_includes { my $self = shift->_get_instance(); my @includes = @_; push( @{$self->{extra_include_dirs}}, @includes ); return; } =head2 push_preprocess_flags Adds given flags to the parameter list for preprocessor invocation. =cut sub push_preprocess_flags { my $self = shift->_get_instance(); my @cpp_flags = @_; push( @{$self->{extra_preprocess_flags}}, @cpp_flags ); return; } =head2 push_compiler_flags Adds given flags to the parameter list for compiler invocation. =cut sub push_compiler_flags { my $self = shift->_get_instance(); my @compiler_flags = @_; my $lang = $self->{lang}; if( scalar( @compiler_flags ) && ( ref($compiler_flags[-1]) eq "HASH" ) ) { my $lang_opt = pop( @compiler_flags ); defined( $lang_opt->{lang} ) or croak( "Missing lang attribute in language options" ); $lang = $lang_opt->{lang}; defined( $self->{lang_supported}->{$lang} ) or croak( "Unsupported language '$lang'" ); } push( @{$self->{extra_compile_flags}->{$lang}}, @compiler_flags ); return; } =head2 push_libraries Adds given list of libraries to the parameter list for linker invocation. =cut sub push_libraries { my $self = shift->_get_instance(); my @libs = @_; push( @{$self->{extra_libs}}, @libs ); return; } =head2 push_library_paths Adds given list of library paths to the parameter list for linker invocation. =cut sub push_library_paths { my $self = shift->_get_instance(); my @libdirs = @_; push( @{$self->{extra_lib_dirs}}, @libdirs ); return; } =head2 push_link_flags Adds given flags to the parameter list for linker invocation. =cut sub push_link_flags { my $self = shift->_get_instance(); my @link_flags = @_; push( @{$self->{extra_link_flags}}, @link_flags ); return; } =head2 compile_if_else( $src [, action-if-true [, action-if-false ] ] ) This function trys to compile specified code and runs action-if-true on success or action-if-false otherwise. Returns a boolean value containing check success state. =cut sub compile_if_else { my ($self, $src, $action_if_true, $action_if_false) = @_; ref $self or $self = $self->_get_instance(); my $builder = $self->_get_builder(); my ($fh, $filename) = tempfile( "testXXXXXX", SUFFIX => '.c'); print {$fh} $src; close $fh; my ($obj_file, $errbuf, $exception); (undef, $errbuf) = capture { eval { $obj_file = $builder->compile( source => $filename, include_dirs => $self->{extra_include_dirs}, extra_compiler_flags => $self->_get_extra_compiler_flags() ); }; $exception = $@; }; unlink $filename; unlink $obj_file if $obj_file; if ($exception || !$obj_file) { $self->_add2log( "compile stage failed" . ( $exception ? " - " . $exception : "" ) ); $errbuf and $self->_add2log( $errbuf ); $self->_add2log( "failing program is:\n" . $src ); defined( $action_if_false ) and "CODE" eq ref( $action_if_false ) and &{$action_if_false}(); return 0; } defined( $action_if_true ) and "CODE" eq ref( $action_if_true ) and &{$action_if_true}(); return 1; } =head2 link_if_else( $src [, action-if-true [, action-if-false ] ] ) This function trys to compile and link specified code and runs action-if-true on success or action-if-false otherwise. Returns a boolean value containing check success state. =cut sub link_if_else { my ($self, $src, $action_if_true, $action_if_false) = @_; ref $self or $self = $self->_get_instance(); my $builder = $self->_get_builder(); my ($fh, $filename) = tempfile( "testXXXXXX", SUFFIX => '.c'); print {$fh} $src; close $fh; my ($obj_file, $errbuf, $exception); (undef, $errbuf) = capture { eval { $obj_file = $builder->compile( source => $filename, include_dirs => $self->{extra_include_dirs}, extra_compiler_flags => $self->_get_extra_compiler_flags() ); }; $exception = $@; }; if ($exception || !$obj_file) { $self->_add2log( "compile stage failed" . ( $exception ? " - " . $exception : "" ) ); $errbuf and $self->_add2log( $errbuf ); $self->_add2log( "failing program is:\n" . $src ); unlink $filename; unlink $obj_file if $obj_file; defined( $action_if_false ) and "CODE" eq ref( $action_if_false ) and &{$action_if_false}(); return 0; } my $exe_file; (undef, $errbuf) = capture { eval { $exe_file = $builder->link_executable( objects => $obj_file, extra_linker_flags => $self->_get_extra_linker_flags() ); }; $exception = $@; }; unlink $filename; unlink $obj_file if $obj_file; unlink $exe_file if $exe_file; if ($exception || !$exe_file) { $self->_add2log( "link stage failed" . ( $exception ? " - " . $exception : "" ) ); $errbuf and $self->_add2log( $errbuf ); $self->_add2log( "failing program is:\n" . $src ); defined( $action_if_false ) and "CODE" eq ref( $action_if_false ) and &{$action_if_false}(); return 0; } defined( $action_if_true ) and "CODE" eq ref( $action_if_true ) and &{$action_if_true}(); return 1; } =head2 check_cached( cache-var, message, sub-to-check ) This function checks whether a specified cache variable is set or not, and if not it's going to set it using specified sub-to-check. =cut sub check_cached { my ($self, $cache_name, $message, $check_sub) = @_; ref $self or $self = $self->_get_instance(); $self->msg_checking( $message ); if( defined($self->{cache}->{$cache_name}) ) { $self->msg_result( "(cached)", $self->{cache}->{$cache_name} ); } else { $self->{cache}->{$cache_name} = &{$check_sub}(); $self->msg_result( $self->{cache}->{$cache_name} ); } return $self->{cache}->{$cache_name}; } =head2 cache_val This functions returns the value of a previously check_cached call. =cut sub cache_val { my $self = shift->_get_instance(); my $cache_name = shift; defined $self->{cache}->{$cache_name} or return; return $self->{cache}->{$cache_name}; } =head2 check_decl( symbol, [action-if-found], [action-if-not-found], [prologue = default includes] ) If symbol (a function, variable or constant) is not declared in includes and a declaration is needed, run the code ref given in I, otherwise I. includes is a series of include directives, defaulting to I, which are used prior to the declaration under test. This method actually tests whether symbol is defined as a macro or can be used as an r-value, not whether it is really declared, because it is much safer to avoid introducing extra declarations when they are not needed. In order to facilitate use of C++ and overloaded function declarations, it is possible to specify function argument types in parentheses for types which can be zero-initialized: Config::AutoConf->check_decl("basename(char *)") This method caches its result in the Cset langE>_symbol variable. =cut sub check_decl { my ($self, $symbol, $action_if_found, $action_if_not_found, $prologue) = @_; $self = $self->_get_instance(); defined( $symbol ) or return; # XXX prefer croak ref( $symbol ) eq "" or return; ( my $sym_plain = $symbol ) =~ s/ *\(.*//; my $sym_call = $symbol; $sym_call =~ s/\(/((/; $sym_call =~ s/\)/) 0)/; $sym_call =~ s/,/) 0, (/g; my $cache_name = $self->_cache_name( "decl", $self->{lang}, $symbol ); my $check_sub = sub { my $body = <lang_build_program( $prologue, $body ); my $have_decl = $self->compile_if_else( $conftest ); if( $have_decl ) { if( defined( $action_if_found ) and "CODE" eq ref( $action_if_found ) ) { &{$action_if_found}(); } } else { if( defined( $action_if_not_found ) and "CODE" eq ref( $action_if_not_found ) ) { &{$action_if_not_found}(); } } return $have_decl; }; return $self->check_cached( $cache_name, "whether $symbol is declared", $check_sub ); } =head2 check_decls( symbols, [action-if-found], [action-if-not-found], [prologue = default includes] ) For each of the symbols (with optional function argument types for C++ overloads), run L. If I is given, it is additional code to execute when one of the symbol declarations is needed, otherwise I is executed. Contrary to GNU autoconf, this method does not declare HAVE_DECL_symbol macros for the resulting C, because it differs as C between compiling languages. =cut sub check_decls { my ($self, $symbols, $action_if_found, $action_if_not_found, $prologue) = @_; $self = $self->_get_instance(); my $have_syms = 1; foreach my $symbol (@$symbols) { $have_syms &= $self->check_decl( $symbol, undef, undef, $prologue ); } if( $have_syms ) { if( defined( $action_if_found ) and "CODE" eq ref( $action_if_found ) ) { &{$action_if_found}(); } } else { if( defined( $action_if_not_found ) and "CODE" eq ref( $action_if_not_found ) ) { &{$action_if_not_found}(); } } return $have_syms; } sub _have_type_define_name { my $type = $_[0]; my $have_name = "HAVE_" . uc($type); $have_name =~ tr/*/P/; $have_name =~ tr/_A-Za-z0-9/_/c; return $have_name; } =head2 check_type (type, [action-if-found], [action-if-not-found], [prologue = default includes]) Check whether type is defined. It may be a compiler builtin type or defined by the includes. I should be a series of include directives, defaulting to I, which are used prior to the type under test. In C, type must be a type-name, so that the expression C is valid (but C is not) If I type is defined, preprocessor macro HAVE_I (in all capitals, with "*" replaced by "P" and spaces and dots replaced by underscores) is defined. This method caches its result in the Ctype variable. =cut sub check_type { my ($self, $type, $action_if_found, $action_if_not_found, $prologue) = @_; $self = $self->_get_instance(); defined( $type ) or return; # XXX prefer croak ref( $type ) eq "" or return; my $cache_name = $self->_cache_type_name( "type", $type ); my $check_sub = sub { my $body = <lang_build_program( $prologue, $body ); my $have_type = $self->compile_if_else( $conftest ); $self->define_var( _have_type_define_name( $type ), $have_type ? $have_type : undef, "defined when $type is available" ); if( $have_type ) { if( defined( $action_if_found ) and "CODE" eq ref( $action_if_found ) ) { &{$action_if_found}(); } } else { if( defined( $action_if_not_found ) and "CODE" eq ref( $action_if_not_found ) ) { &{$action_if_not_found}(); } } return $have_type; }; return $self->check_cached( $cache_name, "for $type", $check_sub ); } =head2 check_types (types, [action-if-found], [action-if-not-found], [prologue = default includes]) For each type L is called to check for type. If I is given, it is additionally executed when all of the types are found. If I is given, it is executed when one of the types is not found. =cut sub check_types { my ($self, $types, $action_if_found, $action_if_not_found, $prologue) = @_; $self = $self->_get_instance(); my $have_types = 1; foreach my $type (@$types) { $have_types &= $self->check_type( $type, undef, undef, $prologue ); } if( $have_types ) { if( defined( $action_if_found ) and "CODE" eq ref( $action_if_found ) ) { &{$action_if_found}(); } } else { if( defined( $action_if_not_found ) and "CODE" eq ref( $action_if_not_found ) ) { &{$action_if_not_found}(); } } return $have_types; } sub _compute_int_compile { my ($self, $expr, $prologue, @decls) = @_; $self = $self->_get_instance(); my( $body, $conftest, $compile_result ); my ($low, $mid, $high) = (0, 0, 0); if( $self->compile_if_else( $self->lang_build_bool_test( $prologue, "((long int)($expr)) >= 0", @decls ) ) ) { $low = $mid = 0; while( 1 ) { if( $self->compile_if_else( $self->lang_build_bool_test( $prologue, "((long int)($expr)) <= $mid", @decls ) ) ) { $high = $mid; last; } $low = $mid + 1; # avoid overflow if( $low <= $mid ) { $low = 0; last; } $mid = $low * 2; } } elsif( $self->compile_if_else( $self->lang_build_bool_test( $prologue, "((long int)($expr)) < 0", @decls ) ) ) { $high = $mid = -1; while( 1 ) { if( $self->compile_if_else( $self->lang_build_bool_test( $prologue, "((long int)($expr)) >= $mid", @decls ) ) ) { $low = $mid; last; } $high = $mid - 1; # avoid overflow if( $mid < $high ) { $high = 0; last; } $mid = $high * 2; } } # perform binary search between $low and $high while( $low <= $high ) { $mid = int( ( $high - $low ) / 2 + $low ); if( $self->compile_if_else( $self->lang_build_bool_test( $prologue, "((long int)($expr)) < $mid", @decls ) ) ) { $high = $mid - 1; } elsif( $self->compile_if_else( $self->lang_build_bool_test( $prologue, "((long int)($expr)) > $mid", @decls ) ) ) { $low = $mid + 1; } else { return $mid; } } return; } =head2 compute_int (expression, [action-if-fails], [prologue = default includes], [@decls]) Returns the value of the integer I. The value should fit in an initializer in a C variable of type signed long. It should be possible to evaluate the expression at compile-time. If no includes are specified, the default includes are used. Execute I if the value cannot be determined correctly. =cut sub compute_int { my ($self, $expr, $action_if_fails, $prologue, @decls) = @_; $self = $self->_get_instance(); my $cache_name = $self->_cache_type_name( "compute_int", $self->{lang}, $expr ); my $check_sub = sub { my $val = $self->_compute_int_compile( $expr, $prologue, @decls); unless( defined( $val ) ) { if( defined( $action_if_fails ) and "CODE" eq ref( $action_if_fails ) ) { &{$action_if_fails}(); } } return $val; }; return $self->check_cached( $cache_name, "for compute result of ($expr)", $check_sub ); } sub _sizeof_type_define_name { my $type = $_[0]; my $have_name = "SIZEOF_" . uc($type); $have_name =~ tr/*/P/; $have_name =~ tr/_A-Za-z0-9/_/c; return $have_name; } =head2 check_sizeof_type (type, [action-if-found], [action-if-not-found], [prologue = default includes]) Checks for the size of the specified type by compiling. If no size can determined, I is invoked when given. Otherwise I is invoked and C is defined using the determined size. In opposition to GNU AutoConf, this method can determine size of structure members, eg. $ac->check_sizeof_type( "SV.sv_refcnt", undef, undef, $include_perl ); # or $ac->check_sizeof_type( "struct utmpx.ut_id", undef, undef, "#include " ); This method caches its result in the Cset langE>_type variable. =cut sub check_sizeof_type { my ($self, $type, $action_if_found, $action_if_not_found, $prologue) = @_; $self = $self->_get_instance(); defined( $type ) or return; # XXX prefer croak ref( $type ) eq "" or return; my $cache_name = $self->_cache_type_name( "sizeof", $self->{lang}, $type ); my $check_sub = sub { my @decls; if( $type =~ m/^([^.]+)\.([^.]+)$/ ) { my $struct = $1; $type = "_ac_test_aggr.$2"; my $decl = "static $struct _ac_test_aggr;"; push( @decls, $decl ); } my $typesize = $self->_compute_int_compile( "sizeof($type)", $prologue, @decls ); $self->define_var( _sizeof_type_define_name( $type ), $typesize ? $typesize : undef, "defined when sizeof($type) is available" ); if( $typesize ) { if( defined( $action_if_found ) and "CODE" eq ref( $action_if_found ) ) { &{$action_if_found}(); } } else { if( defined( $action_if_not_found ) and "CODE" eq ref( $action_if_not_found ) ) { &{$action_if_not_found}(); } } return $typesize; }; return $self->check_cached( $cache_name, "for size of $type", $check_sub ); } =head2 check_sizeof_types (type, [action-if-found], [action-if-not-found], [prologue = default includes]) For each type L is called to check for size of type. If I is given, it is additionally executed when all of the sizes of the types could determined. If I is given, it is executed when one size of the types could not determined. =cut sub check_sizeof_types { my ($self, $types, $action_if_found, $action_if_not_found, $prologue) = @_; $self = $self->_get_instance(); my $have_sizes = 1; foreach my $type (@$types) { $have_sizes &= ! ! ($self->check_sizeof_type ( $type, undef, undef, $prologue )); } if( $have_sizes ) { if( defined( $action_if_found ) and "CODE" eq ref( $action_if_found ) ) { &{$action_if_found}(); } } else { if( defined( $action_if_not_found ) and "CODE" eq ref( $action_if_not_found ) ) { &{$action_if_not_found}(); } } return $have_sizes; } sub _alignof_type_define_name { my $type = $_[0]; my $have_name = "ALIGNOF_" . uc($type); $have_name =~ tr/*/P/; $have_name =~ tr/_A-Za-z0-9/_/c; return $have_name; } =head2 check_alignof_type (type, [action-if-found], [action-if-not-found], [prologue = default includes]) Define ALIGNOF_type to be the alignment in bytes of type. I must be valid as a structure member declaration or I must be a structure member itself. This method caches its result in the Cset langE>_type variable, with I<*> mapped to C

and other characters not suitable for a variable name mapped to underscores. =cut sub check_alignof_type { my ($self, $type, $action_if_found, $action_if_not_found, $prologue) = @_; $self = $self->_get_instance(); defined( $type ) or return; # XXX prefer croak ref( $type ) eq "" or return; my $cache_name = $self->_cache_type_name( "alignof", $self->{lang}, $type ); my $check_sub = sub { my @decls = ( "#ifndef offsetof", "# ifdef __ICC", "# define offsetof(type,memb) ((size_t)(((char *)(&((type*)0)->memb)) - ((char *)0)))", "# else", "# define offsetof(type,memb) ((size_t)&((type*)0)->memb)", "# endif", "#endif" ); my ($struct, $memb); if( $type =~ m/^([^.]+)\.([^.]+)$/ ) { $struct = $1; $memb = $2; } else { push( @decls, "typedef struct { char x; $type y; } ac__type_alignof_;" ); $struct = "ac__type_alignof_"; $memb = "y"; } my $typealign = $self->_compute_int_compile( "offsetof($struct, $memb)", $prologue, @decls ); $self->define_var( _alignof_type_define_name( $type ), $typealign ? $typealign : undef, "defined when alignof($type) is available" ); if( $typealign ) { if( defined( $action_if_found ) and "CODE" eq ref( $action_if_found ) ) { &{$action_if_found}(); } } else { if( defined( $action_if_not_found ) and "CODE" eq ref( $action_if_not_found ) ) { &{$action_if_not_found}(); } } return $typealign; }; return $self->check_cached( $cache_name, "for align of $type", $check_sub ); } =head2 check_alignof_types (type, [action-if-found], [action-if-not-found], [prologue = default includes]) For each type L is called to check for align of type. If I is given, it is additionally executed when all of the aligns of the types could determined. If I is given, it is executed when one align of the types could not determined. =cut sub check_alignof_types { my ($self, $types, $action_if_found, $action_if_not_found, $prologue) = @_; $self = $self->_get_instance(); my $have_aligns = 1; foreach my $type (@$types) { $have_aligns &= ! ! ($self->check_alignof_type ( $type, undef, undef, $prologue )); } if( $have_aligns ) { if( defined( $action_if_found ) and "CODE" eq ref( $action_if_found ) ) { &{$action_if_found}(); } } else { if( defined( $action_if_not_found ) and "CODE" eq ref( $action_if_not_found ) ) { &{$action_if_not_found}(); } } return $have_aligns; } sub _have_member_define_name { my $member = $_[0]; my $have_name = "HAVE_" . uc($member); $have_name =~ tr/_A-Za-z0-9/_/c; return $have_name; } =head2 check_member (member, [action-if-found], [action-if-not-found], [prologue = default includes]) Check whether I is in form of I.I and I is a member of the I aggregate. I should be a series of include directives, defaulting to I, which are used prior to the aggregate under test. Config::AutoConf->check_member( "struct STRUCT_SV.sv_refcnt", undef, sub { Config::AutoConf->msg_failure( "sv_refcnt member required for struct STRUCT_SV" ); } "#include \n#include " ); If I aggregate has I member, preprocessor macro HAVE_I_I (in all capitals, with spaces and dots replaced by underscores) is defined. This macro caches its result in the Caggr_member variable. =cut sub check_member { my ($self, $member, $action_if_found, $action_if_not_found, $prologue) = @_; $self = $self->_get_instance(); defined( $member ) or return; # XXX prefer croak ref( $member ) eq "" or return; $member =~ m/^([^.]+)\.([^.]+)$/ or return; my $type = $1; $member = $2; my $cache_name = $self->_cache_type_name( "member", $type ); my $check_sub = sub { my $body = <lang_build_program( $prologue, $body ); my $have_member = $self->compile_if_else( $conftest ); $self->define_var( _have_member_define_name( $member ), $have_member ? $have_member : undef, "defined when $member is available" ); if( $have_member ) { if( defined( $action_if_found ) and "CODE" eq ref( $action_if_found ) ) { &{$action_if_found}(); } } else { if( defined( $action_if_not_found ) and "CODE" eq ref( $action_if_not_found ) ) { &{$action_if_not_found}(); } } return $have_member; }; return $self->check_cached( $cache_name, "for $type.$member", $check_sub ); } =head2 check_members (members, [action-if-found], [action-if-not-found], [prologue = default includes]) For each member L is called to check for member of aggregate. If I is given, it is additionally executed when all of the aggregate members are found. If I is given, it is executed when one of the aggregate members is not found. =cut sub check_members { my ($self, $members, $action_if_found, $action_if_not_found, $prologue) = @_; $self = $self->_get_instance(); my $have_members = 1; foreach my $member (@$members) { $have_members &= $self->check_member( $member, undef, undef, $prologue ); } if( $have_members ) { if( defined( $action_if_found ) and "CODE" eq ref( $action_if_found ) ) { &{$action_if_found}(); } } else { if( defined( $action_if_not_found ) and "CODE" eq ref( $action_if_not_found ) ) { &{$action_if_not_found}(); } } return $have_members; } =head2 check_headers This function uses check_header to check if a set of include files exist in the system and can be included and compiled by the available compiler. Returns the name of the first header file found. =cut sub check_headers { my $self = shift; for (@_) { return $_ if check_header($self, $_) } return undef; } sub _have_header_define_name { my $header = $_[0]; my $have_name = "HAVE_" . uc($header); $have_name =~ tr/_A-Za-z0-9/_/c; return $have_name; } sub _check_header { my ($self, $header, $prologue, $body) = @_; $prologue .= <<"_ACEOF"; #include <$header> _ACEOF my $conftest = $self->lang_build_program( $prologue, $body ); my $have_header = $self->compile_if_else( $conftest ); return $have_header; } =head2 check_header This function is used to check if a specific header file is present in the system: if we detect it and if we can compile anything with that header included. Note that normally you want to check for a header first, and then check for the corresponding library (not all at once). The standard usage for this module is: Config::AutoConf->check_header("ncurses.h"); This function will return a true value (1) on success, and a false value if the header is not present or not available for common usage. =cut sub check_header { my $self = shift; my $header = shift; my $pre_inc = shift; return 0 unless $header; my $prologue = ""; defined $pre_inc and $prologue .= "$pre_inc\n"; my $cache_name = $self->_cache_name( $header ); my $check_sub = sub { my $have_header = $self->_check_header( $header, $prologue, "" ); $self->define_var( _have_header_define_name( $header ), $have_header ? $have_header : undef, "defined when $header is available" ); return $have_header; }; return $self->check_cached( $cache_name, "for $header", $check_sub ); } =head2 check_all_headers This function checks each given header for usability. =cut sub check_all_headers { my $self = shift->_get_instance(); @_ or return; my $rc = 1; foreach my $header (@_) { $rc &= $self->check_header( $header ); } return $rc; } =head2 check_stdc_headers Checks for standard C89 headers, namely stdlib.h, stdarg.h, string.h and float.h. If those are found, additional all remaining C89 headers are checked: assert.h, ctype.h, errno.h, limits.h, locale.h, math.h, setjmp.h, signal.h, stddef.h, stdio.h and time.h. Returns a false value if it fails. =cut sub check_stdc_headers { my $self = shift->_get_instance(); my $rc = 0; if( $rc = $self->check_all_headers( qw(stdlib.h stdarg.h string.h float.h) ) ) { $rc &= $self->check_all_headers( qw/assert.h ctype.h errno.h limits.h/ ); $rc &= $self->check_all_headers( qw/locale.h math.h setjmp.h signal.h/ ); $rc &= $self->check_all_headers( qw/stddef.h stdio.h time.h/ ); } if( $rc ) { $self->define_var( "STDC_HEADERS", 1, "Define to 1 if you have the ANSI C header files." ); } return $rc; } =head2 check_default_headers This function checks for some default headers, the std c89 haeders and sys/types.h, sys/stat.h, memory.h, strings.h, inttypes.h, stdint.h and unistd.h =cut sub check_default_headers { my $self = shift->_get_instance(); my $rc = $self->check_stdc_headers() and $self->check_all_headers( qw(sys/types.h sys/stat.h memory.h strings.h inttypes.h stdint.h unistd.h) ); return $rc; } =head2 check_dirent_header Check for the following header files. For the first one that is found and defines 'DIR', define the listed C preprocessor macro: dirent.h HAVE_DIRENT_H sys/ndir.h HAVE_SYS_NDIR_H sys/dir.h HAVE_SYS_DIR_H ndir.h HAVE_NDIR_H The directory-library declarations in your source code should look something like the following: #include #ifdef HAVE_DIRENT_H # include # define NAMLEN(dirent) strlen ((dirent)->d_name) #else # define dirent direct # define NAMLEN(dirent) ((dirent)->d_namlen) # ifdef HAVE_SYS_NDIR_H # include # endif # ifdef HAVE_SYS_DIR_H # include # endif # ifdef HAVE_NDIR_H # include # endif #endif Using the above declarations, the program would declare variables to be of type C, not C, and would access the length of a directory entry name by passing a pointer to a C to the C macro. This macro might be obsolescent, as all current systems with directory libraries have C<dirent.hE>>. Programs supporting only newer OS might not need touse this macro. =cut sub check_dirent_header { my $self = shift->_get_instance(); my $cache_name = $self->_cache_name( "header_dirent" ); my $check_sub = sub { my $have_dirent; foreach my $header (qw(dirent.h sys/ndir.h sys/dir.h ndir.h)) { $have_dirent = $self->_check_header( $header, "#include \n", "if ((DIR *) 0) { return 0; }" ); $self->define_var( _have_header_define_name( $header ), $have_dirent ? $have_dirent : undef, "defined when $header is available" ); $have_dirent and $have_dirent = $header and last; } return $have_dirent; }; return $self->check_cached( $cache_name, "for header defining DIR *", $check_sub ); } sub _have_lib_define_name { my $lib = $_[0]; my $have_name = "HAVE_LIB" . uc($lib); $have_name =~ tr/_A-Za-z0-9/_/c; return $have_name; } =head2 check_lm( [ action-if-found ], [ action-if-not-found ] ) This method is used to check if some common C functions are available, and if C<-lm> is needed. Returns the empty string if no library is needed, or the "-lm" string if libm is needed. Actions are only called at the end of the list of tests. If one fails, I is run. Otherwise, I is run. =cut sub check_lm { my ($self, $aif, $ainf) = @_; ref($self) or $self = $self->_get_instance(); my $fail = 0; my $required = ""; for my $func (qw(log2 pow log10 log exp sqrt)) { my $ans = $self->search_libs( $func, ['m'] ); $ans or $fail = 1; ($ans ne "none required") and $required = $ans; } if ($fail) { $ainf && $ainf->() } else { $aif && $aif->() } return $required; } =head2 check_lib( lib, func, [ action-if-found ], [ action-if-not-found ], [ @other-libs ] ) This function is used to check if a specific library includes some function. Call it with the library name (without the lib portion), and the name of the function you want to test: Config::AutoConf->check_lib("z", "gzopen"); It returns 1 if the function exist, 0 otherwise. I and I can be CODE references whereby the default action in case of function found is to define the HAVE_LIBlibrary (all in capitals) preprocessor macro with 1 and add $lib to the list of libraries to link. If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as the I argument: e.g., C<[qw(Xt X11)]>. Otherwise, this routine may fail to detect that library is present, because linking the test program can fail with unresolved symbols. The other-libraries argument should be limited to cases where it is desirable to test for one library in the presence of another that is not already in LIBS. It's recommended to use L instead of check_lib these days. =cut sub check_lib { my ( $self, $lib, $func, $action_if_found, $action_if_not_found, @other_libs ) = @_; ref($self) or $self = $self->_get_instance(); return 0 unless $lib; return 0 unless $func; scalar( @other_libs ) == 1 and ref( $other_libs[0] ) eq "ARRAY" and @other_libs = @{ $other_libs[0] }; my $cache_name = $self->_cache_name( "lib", $lib, $func ); my $check_sub = sub { my $conftest = $self->lang_call( "", $func ); my @save_libs = @{$self->{extra_libs}}; push( @{$self->{extra_libs}}, $lib, @other_libs ); my $have_lib = $self->link_if_else( $conftest ); $self->{extra_libs} = [ @save_libs ]; if( $have_lib ) { if( defined( $action_if_found ) and "CODE" eq ref( $action_if_found ) ) { &{$action_if_found}(); } else { $self->define_var( _have_lib_define_name( $lib ), $have_lib, "defined when library $lib is available" ); push( @{$self->{extra_libs}}, $lib ); } } else { if( defined( $action_if_not_found ) and "CODE" eq ref( $action_if_not_found ) ) { &{$action_if_not_found}(); } else { $self->define_var( _have_lib_define_name( $lib ), undef, "defined when library $lib is available" ); } } return $have_lib; }; return $self->check_cached( $cache_name, "for $func in -l$lib", $check_sub ); } =head2 search_libs( function, search-libs, [action-if-found], [action-if-not-found], [other-libs] ) Search for a library defining function if it's not already available. This equates to calling Config::AutoConf->link_if_else( Config::AutoConf->lang_call( "", "$function" ) ); first with no libraries, then for each library listed in search-libs. I must be specified as an array reference to avoid confusion in argument order. Prepend -llibrary to LIBS for the first library found to contain function, and run I. If the function is not found, run I. If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as the I argument: e.g., C<[qw(Xt X11)]>. Otherwise, this method fails to detect that function is present, because linking the test program always fails with unresolved symbols. The result of this test is cached in the ac_cv_search_function variable as "none required" if function is already available, as C<0> if no library containing function was found, otherwise as the -llibrary option that needs to be prepended to LIBS. =cut sub search_libs { my ( $self, $func, $libs, $action_if_found, $action_if_not_found, @other_libs ) = @_; ref($self) or $self = $self->_get_instance(); ( defined( $libs ) and "ARRAY" eq ref( $libs ) and scalar( @{$libs} ) > 0 ) or return 0; # XXX would prefer croak return 0 unless $func; scalar( @other_libs ) == 1 and ref( $other_libs[0] ) eq "ARRAY" and @other_libs = @{ $other_libs[0] }; my $cache_name = $self->_cache_name( "search", $func ); my $check_sub = sub { my $conftest = $self->lang_call( "", $func ); my @save_libs = @{$self->{extra_libs}}; my $have_lib = 0; foreach my $libstest ( undef, @$libs ) { # XXX would local work on array refs? can we omit @save_libs? $self->{extra_libs} = [ @save_libs ]; defined( $libstest ) and unshift( @{$self->{extra_libs}}, $libstest, @other_libs ); $self->link_if_else( $conftest ) and ( $have_lib = defined( $libstest ) ? $libstest : "none required" ) and last; } $self->{extra_libs} = [ @save_libs ]; if( $have_lib ) { $have_lib eq "none required" or unshift( @{$self->{extra_libs}}, $have_lib ); if( defined( $action_if_found ) and "CODE" eq ref( $action_if_found ) ) { &{$action_if_found}(); } } else { if( defined( $action_if_not_found ) and "CODE" eq ref( $action_if_not_found ) ) { &{$action_if_not_found}(); } } return $have_lib; }; return $self->check_cached( $cache_name, "for library containing $func", $check_sub ); } # # # Auxiliary funcs # sub _sanitize { # This is hard coded, and maybe a little stupid... my $x = shift; $x =~ s/ //g; $x =~ s/\///g; $x =~ s/\\//g; return $x; } sub _get_instance { my $class = shift; ref $class and return $class; defined( $glob_instance ) and ref( $glob_instance ) and return $glob_instance; $glob_instance = $class->new(); return $glob_instance; } sub _get_builder { my $self = $_[0]->_get_instance(); defined( $self->{lang_supported}->{ $self->{lang} } ) or croak( "Unsupported compile language \"" . $self->{lang} . "\"" ); my $builder = $self->{lang_supported}->{ $self->{lang} }->new( quiet => 1 ); ## XXX - Temporarily. Will try to send upstream if ($self->{lang} eq "C") { $builder->{config}{ccflags} =~ s/-arch \S+//g; $builder->{config}{lddlflags} =~ s/-arch \S+//g; $builder->{config}{ldflags} =~ s/-arch \S+//g; } return $builder; } sub _set_language { my $self = shift->_get_instance(); my ($lang, $impl) = @_; defined( $lang ) or croak( "Missing language" ); defined( $impl ) and defined( $self->{lang_supported}->{$lang} ) and $impl ne $self->{lang_supported}->{$lang} and croak( "Language implementor ($impl) doesn't match exisiting one (" . $self->{lang_supported}->{$lang} . ")" ); defined( $impl ) and !defined( $self->{lang_supported}->{$lang} ) and $self->{lang_supported}->{$lang} = $impl; defined( $self->{lang_supported}->{$lang} ) or croak( "Unsupported language \"$lang\"" ); defined( $self->{extra_compile_flags}->{$lang} ) or $self->{extra_compile_flags}->{$lang} = []; $self->{lang} = $lang; return; } sub _fill_defines { my ($self, $src, $action_if_true, $action_if_false) = @_; ref $self or $self = $self->_get_instance(); my $conftest = ""; while( my ($defname, $defcnt) = each( %{ $self->{defines} } ) ) { $defcnt->[0] or next; defined $defcnt->[1] and $conftest .= "/* " . $defcnt->[1] . " */\n"; $conftest .= join( " ", "#define", $defname, $defcnt->[0] ) . "\n"; } $conftest .= "/* end of conftest.h */\n"; return $conftest; } # # default includes taken from autoconf/headers.m4 # =head2 _default_includes returns a string containing default includes for program prologue taken from autoconf/headers.m4: #include #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef HAVE_SYS_STAT_H # include #endif #ifdef STDC_HEADERS # include # include #else # ifdef HAVE_STDLIB_H # include # endif #endif #ifdef HAVE_STRING_H # if !defined STDC_HEADERS && defined HAVE_MEMORY_H # include # endif # include #endif #ifdef HAVE_STRINGS_H # include #endif #ifdef HAVE_INTTYPES_H # include #endif #ifdef HAVE_STDINT_H # include #endif #ifdef HAVE_UNISTD_H # include #endif =cut sub _default_includes { my $conftest .= <<"_ACEOF"; #include #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef HAVE_SYS_STAT_H # include #endif #ifdef STDC_HEADERS # include # include #else # ifdef HAVE_STDLIB_H # include # endif #endif #ifdef HAVE_STRING_H # if !defined STDC_HEADERS && defined HAVE_MEMORY_H # include # endif # include #endif #ifdef HAVE_STRINGS_H # include #endif #ifdef HAVE_INTTYPES_H # include #endif #ifdef HAVE_STDINT_H # include #endif #ifdef HAVE_UNISTD_H # include #endif _ACEOF return $conftest; } sub _default_main { return $_[0]->_build_main(""); } sub _build_main { my $self = shift->_get_instance(); my $body = shift || ""; my $conftest .= <<"_ACEOF"; int main () { $body; return 0; } _ACEOF return $conftest; } sub _cache_prefix { return "ac"; } sub _cache_name { my ($self, @names) = @_; my $cache_name = join( "_", $self->_cache_prefix(), "cv", @names ); $cache_name =~ tr/_A-Za-z0-9/_/c; if( $cache_name eq "ac_cv_0_0" ) { Test::More::diag( "break here" ); } return $cache_name; } sub _get_log_fh { my $self = $_[0]->_get_instance(); unless( defined( $self->{logfh} ) ) { open( $self->{logfh}, ">", $self->{logfile} ) or croak "Could not open file $self->{logfile}: $!"; } return $self->{logfh}; } sub _add2log { my ($self, @logentries) = @_; ref($self) or $self = $self->_get_instance(); $self->_get_log_fh(); foreach my $logentry (@logentries) { print {$self->{logfh}} "$logentry\n"; } return; } sub _cache_type_name { my ($self, @names) = @_; return $self->_cache_name( map { $_ =~ tr/*/p/; $_ } @names ); } sub _get_extra_compiler_flags { my $self = shift->_get_instance(); my @ppflags = @{$self->{extra_preprocess_flags}}; my @cflags = @{$self->{extra_compile_flags}->{ $self->{lang} }}; return join( " ", @ppflags, @cflags ); } sub _get_extra_linker_flags { my $self = shift->_get_instance(); my @libs = @{$self->{extra_libs}}; my @ldflags = @{$self->{extra_link_flags}}; return join( " ", @ldflags, map { "-l$_" } @libs ); } =head1 AUTHOR Alberto Simões, C<< >> Jens Rehsack, C<< >> =head1 NEXT STEPS Although a lot of work needs to be done, this is the next steps I intent to take. - detect flex/lex - detect yacc/bison/byacc - detect ranlib (not sure about its importance) These are the ones I think not too much important, and will be addressed later, or by request. - detect an 'install' command - detect a 'ln -s' command -- there should be a module doing this kind of task. =head1 BUGS A lot. Portability is a pain. B<>. Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 ACKNOWLEDGEMENTS Michael Schwern for kind MacOS X help. Ken Williams for ExtUtils::CBuilder =head1 COPYRIGHT & LICENSE Copyright 2004-2011 by the Authors This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO ExtUtils::CBuilder(3) =cut 1; # End of Config::AutoConf pod-syntax.t100644000000000000 25213321164704 20421 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/xt/author#!perl # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); release000755000000000000 013321164704 16125 5ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/xtmeta-json.t100644000000000000 6413321164704 20307 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/xt/release#!perl use Test::CPAN::Meta::JSON; meta_json_ok(); 00-report-prereqs.dd100644000000000000 1303213321164704 20214 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/tdo { my $x = { 'build' => { 'requires' => { 'Module::Build' => '0.28' } }, 'configure' => { 'requires' => { 'Module::Build' => '0.28' } }, 'develop' => { 'requires' => { 'Code::TidyAll::Plugin::Test::Vars' => '0.02', 'Devel::PPPort' => '3.23', 'File::Temp' => '0', 'JSON' => '0', 'MaxMind::DB::Reader' => '0', 'Parallel::ForkManager' => '1.19', 'Perl::Critic' => '1.126', 'Perl::Tidy' => '20160302', 'Pod::Wordlist' => '0', 'Test::CPAN::Changes' => '0.19', 'Test::CPAN::Meta::JSON' => '0.16', 'Test::CleanNamespaces' => '0.15', 'Test::EOL' => '0', 'Test::Mojibake' => '0', 'Test::More' => '0.96', 'Test::NoTabs' => '0', 'Test::Pod' => '1.41', 'Test::Portability::Files' => '0', 'Test::Requires' => '0', 'Test::Spelling' => '0.12', 'Test::Synopsis' => '0', 'Test::Vars' => '0.009', 'Test::Version' => '2.05', 'lib' => '0', 'utf8' => '0' } }, 'runtime' => { 'requires' => { 'Carp' => '0', 'Data::Dumper::Concise' => '0', 'Data::IEEE754' => '0', 'Digest::MD5' => '0', 'Digest::SHA1' => '0', 'Encode' => '0', 'Exporter' => '0', 'IO::Handle' => '0', 'Math::Int128' => '0.21', 'Math::Int64' => '0.51', 'MaxMind::DB::Common' => '0.031003', 'MaxMind::DB::Metadata' => '0', 'MaxMind::DB::Reader::Decoder' => '0', 'MaxMind::DB::Role::Debugs' => '0', 'Moose' => '0', 'Moose::Util::TypeConstraints' => '0', 'MooseX::Params::Validate' => '0', 'MooseX::StrictConstructor' => '0', 'Net::Works::Network' => '0', 'Sereal::Decoder' => '0', 'Sereal::Encoder' => '3.002', 'Test::Deep::NoTest' => '0', 'XSLoader' => '0', 'autodie' => '0', 'bytes' => '0', 'constant' => '0', 'namespace::autoclean' => '0', 'perl' => '5.013002', 'strict' => '0', 'warnings' => '0' } }, 'test' => { 'recommends' => { 'CPAN::Meta' => '2.120900' }, 'requires' => { 'Data::Printer' => '0', 'Devel::Refcount' => '0', 'ExtUtils::MakeMaker' => '0', 'File::Spec' => '0', 'File::Temp' => '0', 'JSON' => '0', 'List::AllUtils' => '0', 'List::Util' => '0', 'MaxMind::DB::Reader' => '0', 'Net::Works::Address' => '0', 'Scalar::Util' => '0', 'Test::Bits' => '0', 'Test::Builder' => '0', 'Test::Fatal' => '0', 'Test::HexDifferences' => '0', 'Test::MaxMind::DB::Common::Data' => '0', 'Test::More' => '0.96', 'Test::Requires' => '0', 'Test::Warnings' => '0', 'lib' => '0', 'utf8' => '0' } } }; $x; }portability.t100644000000000000 26713321164704 20663 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/xt/authoruse strict; use warnings; use Test::More; eval 'use Test::Portability::Files'; plan skip_all => 'Test::Portability::Files required for testing portability' if $@; run_tests(); DB000755000000000000 013321164704 16442 5ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/lib/MaxMindWriter.pm100644000000000000 577213321164704 20427 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/lib/MaxMind/DBpackage MaxMind::DB::Writer; use strict; use warnings; use 5.013002; our $VERSION = '0.300003'; 1; # ABSTRACT: Create MaxMind DB database files __END__ =pod =encoding UTF-8 =head1 NAME MaxMind::DB::Writer - Create MaxMind DB database files =head1 VERSION version 0.300003 =head1 SYNOPSIS use MaxMind::DB::Writer::Tree; my %types = ( color => 'utf8_string', dogs => [ 'array', 'utf8_string' ], size => 'uint16', ); my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 24, database_type => 'My-IP-Data', languages => ['en'], description => { en => 'My database of IP data' }, map_key_type_callback => sub { $types{ $_[0] } }, ); $tree->insert_network( '8.8.8.0/24', { color => 'blue', dogs => [ 'Fido', 'Ms. Pretty Paws' ], size => 42, }, ); open my $fh, '>:raw', '/path/to/my-ip-data.mmdb'; $tree->write_tree($fh); =head1 DESCRIPTION This distribution contains the code necessary to write L. See L for API docs. =head1 MAC OS X SUPPORT If you're running into install errors under Mac OS X, you may need to force a build of the 64 bit binary. For example, if you're installing via C: ARCHFLAGS="-arch x86_64" cpanm MaxMind::DB::Writer =head1 WINDOWS SUPPORT This distribution does not currently work on Windows. Reasonable patches for Windows support are very welcome. You will probably need to start by making L work on Windows, since we use that module's C API for dealing with 128-bit integers to represent IPv6 addresses numerically. =head1 SUPPORT Please report all issues with this code using the GitHub issue tracker at L. We welcome patches as pull requests against our GitHub repository at L. Bugs may be submitted through L. =head1 AUTHORS =over 4 =item * Olaf Alders =item * Greg Oschwald =item * Dave Rolsky =item * Mark Fowler =back =head1 CONTRIBUTORS =for stopwords Florian Ragwitz Ilya Melamed Jan Bieron Narsimham Chelluri Thomas J Mather William Storey =over 4 =item * Florian Ragwitz =item * Ilya Melamed =item * Jan Bieron =item * Narsimham Chelluri =item * Thomas J Mather =item * William Storey =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2018 by MaxMind, Inc. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut test-version.t100644000000000000 63713321164704 20764 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/xt/authoruse strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::Version 1.09 use Test::Version; my @imports = qw( version_all_ok ); my $params = { is_strict => 1, has_version => 1, multiple => 0, }; push @imports, $params if version->parse( $Test::Version::VERSION ) >= version->parse('1.002'); Test::Version->import(@imports); version_all_ok; done_testing; cpan-changes.t100644000000000000 34413321164704 20762 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/xt/releaseuse strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::CPAN::Changes 0.012 use Test::More 0.96 tests => 1; use Test::CPAN::Changes; subtest 'changes_ok' => sub { changes_file_ok('Changes'); }; Writer000755000000000000 013321164704 17413 5ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DBTree.t100644000000000000 4766613321164704 20702 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writeruse strict; use warnings; use lib 't/lib'; use Test::MaxMind::DB::Writer qw( insert_for_type make_tree_from_pairs ranges_to_data test_tree ); use Test::MaxMind::DB::Writer::Iterator (); use Test::Fatal; use Test::More; use Test::Warnings qw( :all ); use MaxMind::DB::Writer::Tree (); use Net::Works::Address (); use Net::Works::Network (); { my @ipv4_subnets = Net::Works::Network->range_as_subnets( '1.1.1.1', '1.1.1.32' ); _test_subnet_permutations( \@ipv4_subnets, 'IPv4' ); } { my @ipv4_subnets = ( Net::Works::Network->range_as_subnets( '1.1.1.1', '1.1.1.32' ), Net::Works::Network->range_as_subnets( '16.1.1.1', '16.1.3.2' ), ); _test_subnet_permutations( \@ipv4_subnets, 'IPv4 - two distinct ranges' ); } { my @ipv6_subnets = Net::Works::Network->range_as_subnets( '::1:ffff:ffff', '::2:0000:0059' ); _test_subnet_permutations( \@ipv6_subnets, 'IPv6' ); } { my @ipv6_subnets = ( Net::Works::Network->range_as_subnets( '::1:ffff:ffff', '::2:0000:0001' ), Net::Works::Network->range_as_subnets( '2002::abcd', '2002::abd4', ) ); _test_subnet_permutations( \@ipv6_subnets, 'IPv6 - two distinct ranges' ); } { my ( $insert, $expect ) = ranges_to_data( [ [ '1.1.1.0', '1.1.1.15' ], [ '1.1.1.1', '1.1.1.32' ], ], [ [ '1.1.1.0', '1.1.1.0' ], [ '1.1.1.1', '1.1.1.32' ], ], ); _test_tree_as_ipv4_and_ipv6( $insert, $expect, 'overlapping subnets - first is lower' ); } { my ( $insert, $expect ) = ranges_to_data( [ [ '1.1.1.0', '1.1.1.15' ], [ '1.1.1.14', '1.1.1.32' ], ], [ [ '1.1.1.0', '1.1.1.13' ], [ '1.1.1.14', '1.1.1.32' ], ], ); _test_tree_as_ipv4_and_ipv6( $insert, $expect, 'overlapping subnets - overlap breaks up first subnet into smaller chunks' ); } { my ( $insert, $expect ) = ranges_to_data( [ [ '1.1.1.1', '1.1.1.32' ], [ '1.1.1.0', '1.1.1.15' ], ], [ [ '1.1.1.0', '1.1.1.15' ], [ '1.1.1.16', '1.1.1.32' ], ], ); _test_tree_as_ipv4_and_ipv6( $insert, $expect, 'overlapping subnets - first is higher' ); } { my ( $insert, $expect ) = ranges_to_data( [ [ '1.1.1.0', '1.1.1.15' ], [ '1.1.1.1', '1.1.1.14' ], ], [ [ '1.1.1.0', '1.1.1.0' ], [ '1.1.1.1', '1.1.1.14' ], [ '1.1.1.15', '1.1.1.15' ], ], ); _test_tree_as_ipv4_and_ipv6( $insert, $expect, 'first subnet contains second subnet' ); } { my ( $insert, $expect ) = ranges_to_data( [ [ '1.1.1.1', '1.1.1.14' ], [ '1.1.1.0', '1.1.1.15' ], ], [ [ '1.1.1.0', '1.1.1.15' ], ], ); _test_tree_as_ipv4_and_ipv6( $insert, $expect, 'second subnet contains first subnet' ); } { my @pairs = ( [ Net::Works::Network->new_from_string( string => '0.0.0.0/32' ), { ip => '0.0.0.0' } ] ); test_tree( \@pairs, \@pairs, '0.0.0.0/32 network', # We're trying to insert into reserved space, which fails unless we # turn off this option since it is reserved! { remove_reserved_networks => 0 }, ); } { my @pairs = ( [ Net::Works::Network->new_from_string( string => '::0.0.0.0/128' ), { ip => '0.0.0.0' } ] ); test_tree( \@pairs, \@pairs, '::0.0.0.0/128 network', # We're trying to insert into reserved space, which fails unless we # turn off this option since it is reserved! { remove_reserved_networks => 0 }, ); } subtest '::/0 insertion' => sub { my $data = { ip => '::' }; my $tree = make_tree_from_pairs( 'network', [ [ '::/0' => $data ] ], # ::/0 contains networks we add as FIXED_EMPTY when this option is on. # As a result, we hit the branch where we silently ignore the insert # (current_bit > network->prefix_length in # insert_record_into_next_node()). This means we create the tree but # the insert was ignored, causing the lookup we're trying to test to # fail. So we turn off adding the FIXED_EMPTY networks to let this test # pass. { remove_reserved_networks => 0 }, ); is_deeply( $tree->lookup_ip_address('::'), $data, ':: is in tree' ); is_deeply( $tree->lookup_ip_address('9000::'), $data, '9000:: is in tree' ); }; # Tests handling of inserting multiple networks that all have the same data - # if we end up with a node that has two identical data records, we want to # remove that node entirely and move the data record up to the parent. subtest 'test merging nodes' => sub { my @distinct_subnets = Net::Works::Network->new_from_string( string => '128.0.0.0/1' ) ->split; for my $type ( 'network', 'range' ) { for my $split_count ( 2 ... 8 ) { my $tree = _create_and_insert_duplicates( $type, $split_count, \@distinct_subnets ); is( $tree->node_count(), 2, 'duplicates merged for split count of ' . $split_count ); for my $ip ( '0.1.2.3', '13.1.0.0', '126.255.255.255' ) { my $address = Net::Works::Address->new_from_string( string => $ip ); is( $tree->lookup_ip_address($address), 'duplicate', qq{$address data value is 'duplicate' for split count $split_count} ); } for my $subnet (@distinct_subnets) { my $first = $subnet->first(); my $value = $first->as_string(); for my $address ( $first, $first->next_ip() ) { is( $tree->lookup_ip_address($address), $value, qq{$address data value is $value for split count of $split_count} ); } } } } }; subtest 'Inserting invalid networks and ranges' => sub { my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test tree' }, merge_strategy => 'toplevel', map_key_type_callback => sub { 'utf8_string' }, alias_ipv6_to_ipv4 => 1, ); like( exception { $tree->insert_range( '2002::', '2001::', {} ) }, qr/in range comes before last IP /, 'First IP after last IP in range' ); like( exception { $tree->insert_range( '2001:', '2002:', {} ) }, qr/Invalid IP/, 'invalid IP in range' ); like( exception { $tree->insert_network( '2001:/129', {} ) }, qr/Invalid network/, 'prefix length too large' ); like( exception { $tree->insert_network( '2001:/-1', {} ) }, qr/Invalid network/, 'negative prefix length' ); like( exception { $tree->insert_network( '2001:/1', {} ) }, qr/Invalid IP/, 'invalid IP in network' ); like( exception { $tree->insert_network( '2002::/16', {} ) }, qr/Attempted to overwrite an aliased network/, 'Received exception when inserting an aliased network' ); $tree->insert_network( '2002::/12', {} ); is_deeply( $tree->lookup_ip_address('2002::1'), undef, 'Insert containing aliased network is silently ignored in the aliased part', ); is_deeply( $tree->lookup_ip_address('2000::1'), {}, 'Insert containing aliased network succeeds outside the aliased part', ); like( exception { $tree->insert_network( '2002:0101:0101:0101::/64', {} ) }, qr/Attempted to insert into an aliased network/, 'Received exception when inserting into alias' ); $tree->insert_network( '192.168.0.0/16', { a => 'b' } ); is_deeply( $tree->lookup_ip_address('192.168.0.1'), undef, 'Insert trying to overwrite reserved network set fixed empty is silently ignored', ); $tree->insert_network( '192.0.0.0/8', { a => 'b' } ); is_deeply( $tree->lookup_ip_address('192.168.10.1'), undef, 'Insert containing reserved network set fixed empty is silently ignored in the reserved part', ); is_deeply( $tree->lookup_ip_address('192.1.10.1'), { a => 'b' }, 'Insert containing reserved network set fixed empty succeeds outside the reserved part', ); $tree->insert_network( '192.168.10.0/24', { a => 'b' } ); is_deeply( $tree->lookup_ip_address('192.168.10.1'), undef, 'Insert into reserved network set fixed empty is silently ignored', ); }; subtest 'Recording merging at /0' => sub { my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test tree' }, merge_strategy => 'toplevel', map_key_type_callback => sub { 'utf8_string' }, # These are 0 to as enabling them will create more than one network alias_ipv6_to_ipv4 => 0, # We can't insert ::/1 since it is reserved if we have this option to # remove the reserved networks on. remove_reserved_networks => 0, ); my $data = { data => 1 }; $tree->insert_network( '::/1', $data ); $tree->insert_network( '8000::/1', $data ); for my $ip ( '::', '2000::', '8000::', '9000::' ) { is_deeply( $tree->lookup_ip_address($ip), $data, "expected data for $ip" ); } }; subtest 'Setting data on a fixed node' => sub { my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test tree' }, merge_strategy => 'none', map_key_type_callback => sub { 'utf8_string' }, # ::/96 gets added as a fixed node when we use `alias_ipv6_to_ipv4' alias_ipv6_to_ipv4 => 1, # This is irrelevant to this test. remove_reserved_networks => 0, ); my $ip = '::/96'; my $data = { hi => 'there' }; $tree->insert_network( $ip, $data ); my $iterator = Test::MaxMind::DB::Writer::Iterator->new(6); $tree->iterate($iterator); is_deeply( [ map { [ $_->[0]->as_string, $_->[1] ] } @{ $iterator->{data_records} } ], [ # This is a little odd but I think makes sense because we refuse to # touch the fixed node. Its left record (::/97) and right record # (::128.0.0.0/97 AKA ::8000:0/97) point to the data. [ '::0/97', $data ], [ '::128.0.0.0/97', $data ], ], 'saw expected data records', ); my @ips_in_tree = ( '::0.0.0.0', '::0.0.0.1', '::128.0.0.0', '::128.0.0.1', ); for my $i (@ips_in_tree) { is_deeply( $tree->lookup_ip_address($i), $data, "$i is in tree" ); } my @ips_not_in_tree = ( '8000::1', ); for my $i (@ips_not_in_tree) { is_deeply( $tree->lookup_ip_address($i), undef, "$i is not in tree" ); } }; subtest 'Setting data on non-fixed node' => sub { my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test tree' }, merge_strategy => 'none', map_key_type_callback => sub { 'utf8_string' }, # Not relevant. alias_ipv6_to_ipv4 => 0, # This is irrelevant to this test. remove_reserved_networks => 0, ); is_deeply( $tree->lookup_ip_address('8000::1'), undef, '8000::1 is not in tree', ); my $data0 = { hi => 'there' }; my $data1 = { hello => 'there' }; $tree->insert_network( '8000::/2', $data0 ); $tree->insert_network( 'C000::/2', $data1 ); my $iterator = Test::MaxMind::DB::Writer::Iterator->new(6); $tree->iterate($iterator); is_deeply( [ map { [ $_->[0]->as_string, $_->[1] ] } @{ $iterator->{data_records} } ], [ [ '8000::/2', $data0 ], [ 'c000::/2', $data1 ], ], 'saw expected data records', ); is_deeply( $tree->lookup_ip_address('8000::1'), $data0, '8000::1 is in tree', ); }; subtest 'Removing regular networks' => sub { my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test tree' }, merge_strategy => 'none', map_key_type_callback => sub { 'utf8_string' }, # Having these off starts us with a very empty tree alias_ipv6_to_ipv4 => 0, remove_reserved_networks => 0, ); like( exception { _node_is_in_tree( $tree, '8000::/1' ) }, qr/Iteration is not currently allowed in trees with no nodes/, 'no nodes in the tree', ); my $data = { hi => 'there' }; $tree->insert_network( 'aaaa::/64', $data ); is_deeply( $tree->lookup_ip_address('aaaa::1'), $data, 'record is in tree', ); ok( _node_is_in_tree( $tree, '8000::/1' ), '8000::/1 is in the tree' ); $tree->remove_network('::/0'); is_deeply( $tree->lookup_ip_address('aaaa::1'), undef, 'record is no longer in tree', ); # After removing it, trimming removes all the way up. like( exception { _node_is_in_tree( $tree, '8000::/1' ) }, qr/Iteration is not currently allowed in trees with no nodes/, 'no nodes in the tree', ); }; subtest 'Removing fixed node' => sub { my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test tree' }, merge_strategy => 'none', map_key_type_callback => sub { 'utf8_string' }, alias_ipv6_to_ipv4 => 1, ); # We have lots of fixed nodes because of both alias_ipv6_to_ipv4 and # because of the fixed emptys from remove_reserved_networks. ok( _node_is_in_tree( $tree, '8000::/1' ), '8000::/1 is in the tree' ); $tree->remove_network('::/0'); ok( _node_is_in_tree( $tree, '8000::/1' ), '8000::/1 is in the tree' ); }; subtest 'Inserting beside fixed empty record' => sub { my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test tree' }, merge_strategy => 'none', map_key_type_callback => sub { 'utf8_string' }, ); my $data = { hi => 'there' }; # ff00::/8 is a fixed empty # Left of it is_deeply( $tree->lookup_ip_address('fe00::1'), undef, 'fe00::1 is not in tree', ); $tree->insert_network( 'fe00::/8', $data ); is_deeply( $tree->lookup_ip_address('fe00::1'), $data, 'fe00::1 is in tree', ); # 100::/64 is a fixed empty # Right of it is_deeply( $tree->lookup_ip_address('100:0:0:1::1'), undef, '100:0:0:1::1 is not in tree', ); $tree->insert_network( '100:0:0:1::/64', $data ); is_deeply( $tree->lookup_ip_address('100:0:0:1::1'), $data, '100:0:0:1::1 is in tree', ); # Above and right of it is_deeply( $tree->lookup_ip_address('100:0:0:2::1'), undef, '100:0:0:2::1 is not in tree', ); $tree->insert_network( '100:0:0:2::/63', $data ); is_deeply( $tree->lookup_ip_address('100:0:0:2::1'), $data, '100:0:0:2::1 is in tree', ); # 2001:db8::/32 is a fixed empty # Above and left of it is_deeply( $tree->lookup_ip_address('2001:db7::1'), undef, '2001:db7::1 is not in tree', ); $tree->insert_network( '2001:db7::/31', $data ); is_deeply( $tree->lookup_ip_address('2001:db7::1'), $data, '2001:db7::1 is in tree', ); }; done_testing(); sub _node_is_in_tree { my $tree = shift; my $network = shift; my $iterator = Test::MaxMind::DB::Writer::Iterator->new(6); $tree->iterate($iterator); my @recs = grep { $_->as_string eq $network } @{ $iterator->{node_records} }; return @recs > 0; } sub _test_subnet_permutations { my $subnets = shift; my $desc = shift; my $id = 0; my @expect = map { [ $_, { foo => 42, id => $id++ } ] } @{$subnets}; { # In this case what we insert into the tree matches the order of what # we expect test_tree( \@expect, \@expect, "ordered subnets - $desc", ); } { my @reversed = reverse @expect; test_tree( \@reversed, \@expect, "reversed subnets - $desc" ); } { my @odd = grep { $_ % 2 } 0 .. $#expect; my @even = grep { !( $_ % 2 ) } 0 .. $#expect; my @shuffled = ( @expect[@odd], @expect[ reverse @even ] ); test_tree( \@shuffled, \@expect, "shuffled subnets - $desc" ); } { my @duplicated = ( @expect, @expect ); test_tree( \@duplicated, \@expect, "duplicated subnets - $desc" ); } } sub _test_tree_as_ipv4_and_ipv6 { my $insert = shift; my $expect = shift; my $desc = shift; test_tree( $insert, $expect, $desc ); _test_tree_as_ipv6( $insert, $expect, $desc ); } sub _test_tree_as_ipv6 { my $insert = shift; my $expect = shift; my $desc = shift; $insert = [ map { [ _subnet_as_v6( $_->[0] ), $_->[1] ] } @{$insert} ]; $expect = [ map { [ _subnet_as_v6( $_->[0] ), $_->[1] ] } @{$expect} ]; test_tree( $insert, $expect, $desc . ' - IPv6' ); } sub _subnet_as_v6 { my $subnet = shift; my $subnet_string = '::' . $subnet->first()->as_string() . '/' . ( $subnet->prefix_length() + 96 ); return Net::Works::Network->new_from_string( string => $subnet_string, version => 6, ); } sub _create_and_insert_duplicates { my $type = shift; my $split_count = shift; my $distinct_subnets = shift; my $tree = make_tree_from_pairs( $type, [ map { [ $_, $_->as_string() ] } @{$distinct_subnets} ], # We happen to insert into reserved networks here and in the tests that # call us, so don't prevent that. { remove_reserved_networks => 0 }, ); my @duplicate_data_subnets = ( Net::Works::Network->new_from_string( string => '0.0.0.0/1' ) ); @duplicate_data_subnets = map { $_->split() } @duplicate_data_subnets for ( 1 .. $split_count ); for my $subnet (@duplicate_data_subnets) { insert_for_type( $tree, $type, $subnet, 'duplicate' ); } for my $subnet (@$distinct_subnets) { insert_for_type( $tree, $type, $subnet, $subnet->first->as_string ); } return $tree; } Util.t100644000000000000 57213321164704 20641 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writeruse strict; use warnings; use MaxMind::DB::Writer::Util qw( key_for_data ); use Test::More; { # Test that refcount does not affect the key. (It did previously.) my $array1 = [ 0, 0 ]; my @array2 = ( 0, 0 ); is( key_for_data($array1), key_for_data( \@array2 ), 'two generations of structure generate same key' ); } done_testing(); dev-bin000755000000000000 013321164704 15376 5ustar00rootroot000000000000MaxMind-DB-Writer-0.300003clang-format-all.sh100755000000000000 21613321164704 21174 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/dev-bin#!/bin/sh format="clang-format -i -style=file" for file in "c/tree.c" "c/tree.h" "lib/MaxMind/DB/Writer/Tree.xs"; do $format $file done clean-namespaces.t100644000000000000 57413321164704 21521 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/xt/authoruse strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::CleanNamespaces 0.006 use Test::More 0.94; use Test::CleanNamespaces 0.15; subtest all_namespaces_clean => sub { namespaces_clean( grep { my $mod = $_; not grep { $mod =~ $_ } qr/MaxMind::DB::Writer::Util/ } Test::CleanNamespaces->find_modules ); }; done_testing; Writer000755000000000000 013321164704 17716 5ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/lib/MaxMind/DBTree.pm100644000000000000 6646413321164704 21353 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/lib/MaxMind/DB/Writerpackage MaxMind::DB::Writer::Tree; use strict; use warnings; use namespace::autoclean; use autodie; our $VERSION = '0.300003'; use IO::Handle; use Math::Int64 0.51; use Math::Int128 0.21 qw( uint128 ); use MaxMind::DB::Common 0.031003 qw( DATA_SECTION_SEPARATOR METADATA_MARKER ); use MaxMind::DB::Metadata; use MaxMind::DB::Writer::Serializer; use MaxMind::DB::Writer::Util qw( key_for_data ); use MooseX::Params::Validate qw( validated_list ); use Sereal::Decoder qw( decode_sereal ); use Sereal::Encoder qw( encode_sereal ); use Moose; use Moose::Util::TypeConstraints; use MooseX::StrictConstructor; use XSLoader; ## no critic (ProhibitCallsToUnexportedSubs) XSLoader::load( __PACKAGE__, $VERSION ); ## use critic has ip_version => ( is => 'ro', isa => 'Int', required => 1, ); #<<< my $RecordSizeType = subtype as 'Int', where { ( $_ % 4 == 0 ) && $_ >= 24 && $_ <= 128 }, message { 'The record size must be a number from 24-128 that is divisible by 4'; }; #>>> has record_size => ( is => 'ro', isa => $RecordSizeType, required => 1, ); my $MergeStrategyEnum = enum( [qw( add-only-if-parent-exists none recurse toplevel )] ); has merge_strategy => ( is => 'ro', isa => $MergeStrategyEnum, lazy => 1, default => 'none', ); has remove_reserved_networks => ( is => 'ro', isa => 'Bool', default => 1, ); has _tree => ( is => 'ro', lazy => 1, builder => '_build_tree', predicate => '_has_tree', ); # All records in the tree will point to a value of this type in the data # section. has _root_data_type => ( is => 'ro', isa => 'Str', # XXX - should make sure it's valid type init_arg => 'root_data_type', default => 'map', ); has map_key_type_callback => ( is => 'ro', isa => 'CodeRef', required => 1, ); has database_type => ( is => 'ro', isa => 'Str', required => 1, ); has languages => ( is => 'ro', isa => 'ArrayRef[Str]', default => sub { [] }, ); has description => ( is => 'ro', isa => 'HashRef[Str]', required => 1, ); has alias_ipv6_to_ipv4 => ( is => 'ro', isa => 'Bool', default => 0, ); has _serializer => ( is => 'ro', isa => 'MaxMind::DB::Writer::Serializer', init_arg => undef, lazy => 1, builder => '_build_serializer', ); # This is an attribute so that we can explicitly set it from test code when we # want to compare the binary output for two trees that we want to be # identical. has _build_epoch => ( is => 'rw', writer => '_set_build_epoch', isa => 'Int', lazy => 1, default => sub { time() }, ); around BUILDARGS => sub { my $orig = shift; my $class = shift; my $args = $class->$orig(@_); if ( exists $args->{merge_record_collisions} ) { warn 'merge_record_collisions is deprecated. Use merge_strategy instead.'; } return $args unless exists $args->{merge_record_collisions}; my $merge_record_collisions = delete $args->{merge_record_collisions}; if ( $args->{merge_strategy} && !( $args->{merge_strategy} eq 'none' xor $merge_record_collisions ) ) { die sprintf( 'merge_strategy cannot be "%s" if merge_record_collisions is "%s"', $args->{merge_strategy}, $args->{merge_record_collisions} ); } $args->{merge_strategy} //= $merge_record_collisions ? 'toplevel' : 'none'; return $args; }; # The XS code expects $self->{_tree} to be populated. sub BUILD { $_[0]->_tree(); } sub _build_tree { my $self = shift; return _create_tree( $self->ip_version, $self->record_size, $self->merge_strategy, $self->alias_ipv6_to_ipv4, $self->remove_reserved_networks, ); } sub merge_record_collisions { warn 'merge_record_collisions is deprecated and will be removed in a future release'; return $_[0]->merge_strategy ne 'none'; } sub insert_network { my $self = shift; my $network = shift; my $data = shift; my $args = shift // {}; my ( $ip_address, $prefix_length ) = split qr{/}, $network, 2; if ( !defined $prefix_length || int($prefix_length) != $prefix_length || $prefix_length < 0 || $prefix_length > 128 ) { die "Invalid network inserted: $network"; } my $merge_strategy = %{$args} ? $self->_merge_strategy($args) : q{}; $self->_insert_network( $ip_address, $prefix_length, key_for_data($data), $data, $merge_strategy, ); return; } sub insert_range { my $self = shift; my $start_ip_address = shift; my $end_ip_address = shift; my $data = shift; my $args = shift // {}; my $merge_strategy = %{$args} ? $self->_merge_strategy($args) : q{}; $self->_insert_range( $start_ip_address, $end_ip_address, key_for_data($data), $data, $merge_strategy, ); return; } sub _merge_strategy { my $self = shift; my $args = shift; if ( ( $args->{insert_only_if_parent_exists} ? 1 : 0 ) + ( $args->{force_overwrite} ? 1 : 0 ) + ( $args->{merge_strategy} ? 1 : 0 ) > 1 ) { die 'Only one of merge_strategy, force_overwrite, or ' . 'insert_only_if_parent_exists can be set at a time'; } if ( $args->{insert_only_if_parent_exists} ) { warn 'The argument insert_only_if_parent_exists is deprecated. ' . 'Use the merge_strategy "add-if-parent-exists" instead.'; return 'add-only-if-parent-exists'; } if ( $args->{force_overwrite} ) { warn 'The argument force_overwrite is deprecated. ' . 'Use the merge_strategy "none" instead.'; return 'none'; } return undef unless $args->{merge_strategy}; die "Unknown merge strategy: $args->{merge_strategy}" unless $MergeStrategyEnum->check( $args->{merge_strategy} ); return $args->{merge_strategy}; } sub remove_network { my $self = shift; my $network = shift; my ( $ip_address, $prefix_length ) = split qr{/}, $network, 2; $self->_remove_network( $ip_address, $prefix_length, ); return; } sub _build_serializer { my $self = shift; return MaxMind::DB::Writer::Serializer->new( map_key_type_callback => $self->map_key_type_callback(), ); } sub write_tree { my $self = shift; my $output = shift; $self->_write_search_tree( $output, $self->_root_data_type(), $self->_serializer(), ); $output->print( DATA_SECTION_SEPARATOR, ${ $self->_serializer()->buffer() }, METADATA_MARKER, $self->_encoded_metadata(), ); } { my %key_types = ( binary_format_major_version => 'uint16', binary_format_minor_version => 'uint16', build_epoch => 'uint64', database_type => 'utf8_string', description => 'map', ip_version => 'uint16', languages => [ 'array', 'utf8_string' ], node_count => 'uint32', record_size => 'uint16', ); my $type_callback = sub { return $key_types{ $_[0] } || 'utf8_string'; }; sub _encoded_metadata { my $self = shift; my $metadata = MaxMind::DB::Metadata->new( binary_format_major_version => 2, binary_format_minor_version => 0, build_epoch => uint128( $self->_build_epoch() ), database_type => $self->database_type(), description => $self->description(), ip_version => $self->ip_version(), languages => $self->languages(), node_count => $self->node_count(), record_size => $self->record_size(), ); my $serializer = MaxMind::DB::Writer::Serializer->new( map_key_type_callback => $type_callback, ); $serializer->store_data( 'map', $metadata->metadata_to_encode() ); return ${ $serializer->buffer() }; } } { my %do_not_freeze = map { $_ => 1 } qw( map_key_type_callback _tree ); sub freeze_tree { my $self = shift; my $filename = shift; my %constructor_params; for my $attr ( $self->meta()->get_all_attributes() ) { next unless $attr->init_arg(); next if $do_not_freeze{ $attr->name() }; my $reader = $attr->get_read_method(); $constructor_params{ $attr->init_arg() } = $self->$reader(); } my $frozen = encode_sereal( \%constructor_params ); $self->_freeze_tree( $filename, $frozen, length $frozen ); return; } } sub new_from_frozen_tree { my $class = shift; my ( $filename, $callback, $database_type, $description, $merge_strategy, $record_size ) = validated_list( \@_, filename => { isa => 'Str' }, map_key_type_callback => { isa => 'CodeRef' }, database_type => { isa => 'Str', optional => 1 }, description => { isa => 'HashRef[Str]', optional => 1 }, merge_strategy => { isa => $MergeStrategyEnum, optional => 1 }, record_size => { isa => $RecordSizeType, optional => 1 }, ); ## no critic (InputOutput::RequireBriefOpen) open my $fh, '<:raw', $filename or die $!; my $packed_params_size; unless ( read( $fh, $packed_params_size, 4 ) == 4 ) { die "Could not read 4 bytes from $filename: $!"; } my $params_size = unpack( 'L', $packed_params_size ); my $frozen_params; unless ( read( $fh, $frozen_params, $params_size ) == $params_size ) { die "Could not read $params_size bytes from $filename: $!"; } close $fh or die $!; my $params = decode_sereal($frozen_params); $params->{database_type} = $database_type if defined $database_type; $params->{description} = $description if defined $description; $params->{record_size} = $record_size if defined $record_size; if ( defined $merge_strategy ) { $params->{merge_strategy} = $merge_strategy; } elsif ( $params->{merge_record_collisions} ) { # This is for backwards compatibility with frozen trees created before # "merge_strategy" was added. $params->{merge_strategy} = 'toplevel'; } my $tree = _thaw_tree( $filename, $params_size + 4, @{$params}{ qw( ip_version record_size merge_strategy alias_ipv6_to_ipv4 remove_reserved_networks ) }, ); return $class->new( %{$params}, map_key_type_callback => $callback, _tree => $tree, ); } sub DEMOLISH { my $self = shift; $self->_free_tree() if $self->_has_tree(); return; } __PACKAGE__->meta()->make_immutable(); 1; # ABSTRACT: Tree representing a MaxMind DB database in memory - then write it to a file __END__ =pod =encoding UTF-8 =head1 NAME MaxMind::DB::Writer::Tree - Tree representing a MaxMind DB database in memory - then write it to a file =head1 VERSION version 0.300003 =head1 SYNOPSIS use MaxMind::DB::Writer::Tree; my %types = ( color => 'utf8_string', dogs => [ 'array', 'utf8_string' ], size => 'uint16', ); my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 24, database_type => 'My-IP-Data', languages => ['en'], description => { en => 'My database of IP data' }, map_key_type_callback => sub { $types{ $_[0] } }, ); $tree->insert_network( '8.8.8.0/24', { color => 'blue', dogs => [ 'Fido', 'Ms. Pretty Paws' ], size => 42, }, ); open my $fh, '>:raw', '/path/to/my-ip-data.mmdb'; $tree->write_tree($fh); =head1 DESCRIPTION This is the main class you'll use to write L. This class represents the database in memory. Once you've created the full tree you can write to a file. =head1 API This class provides the following methods: =head2 MaxMind::DB::Writer::Tree->new() This creates a new tree object. The constructor accepts the following parameters: =over 4 =item * ip_version The IP version for the database. It must be 4 or 6. This parameter is required. =item * record_size This is the record size in I. This should be one of 24, 28, 32 (in theory any number divisible by 4 up to 128 will work but the available readers all expect 24-32). This parameter is required. =item * database_type This is a string containing the database type. This can be anything, really. MaxMind uses strings like "GeoIP2-City", "GeoIP2-Country", etc. This parameter is required. =item * languages This should be an array reference of languages used in the database, like "en", "zh-TW", etc. This is useful as metadata for database readers and end users. This parameter is optional. =item * description This is a hashref where the keys are language names and the values are descriptions of the database in that language. For example, you might have something like: { en => 'My IP data', fr => q{Mon Data d'IP}, } This parameter is required. =item * map_key_type_callback This is a subroutine reference that is called in order to determine how to store each value in a map (hash) data structure. See L below for more details. This parameter is required. =item * merge_record_collisions By default, when an insert collides with a previous insert, the new data simply overwrites the old data where the two networks overlap. If this is set to true, then on a collision, the writer will merge the old data with the new data. The merge strategy employed is controlled by the C attribute, described below. This parameter is optional. It defaults to false unless C is set to something other than C. This parameter is deprecated. New code should just set C directly. B instead.> =item * merge_strategy Controls what merge strategy is employed. =over 8 =item * none No merging will be done. C must either be not set or set to false. =item * toplevel If both data structures are hashrefs then the data from the top level keys in the new data structure are copied over to the existing data structure, potentially replacing any existing values for existing keys completely. =item * recurse Recursively merges the new data structure with the old data structure. Hash values and array elements are either - in the case of simple values - replaced with the new values, or - in the case of complex structures - have their values recursively merged. For example if this data is originally inserted for an IP range: { families => [ { husband => 'Fred', wife => 'Wilma', }, ], year => 1960, } And then this subsequent data is inserted for a range covered by the previous IP range: { families => [ { wife => 'Wilma', child => 'Pebbles', }, { husband => 'Barney', wife => 'Betty', child => 'Bamm-Bamm', }, ], company => 'Hanna-Barbera Productions', } Then querying within the range will produce the results: { families => [ { husband => 'Fred', wife => 'Wilma', # note replaced value child => 'Pebbles', }, { husband => 'Barney', wife => 'Betty', child => 'Bamm-Bamm', }, ], year => 1960, company => 'Hanna-Barbera Productions', } =item * add-only-if-parent-exists With this merge strategy, data will only be inserted when there is already a record for the network (or sub-network). Similarly, when merging the data record with an existing data record, no new hash or array references will be created within the data record for the new data. For instance, if the original data record is C<{parent_a => {sibling => 1}}> and C<{parent_a => {child_a => 1}, parent_b => {child_b => 1}}> is inserted, only C, not C, will appear in the merged record. This option is intended to be used when inserting data that supplements existing data but that is not independently useful. =back In all merge strategies attempting to merge two differing data structures causes an exception. This parameter is optional. If C is true, this defaults to C; otherwise, it defaults to C. =item * alias_ipv6_to_ipv4 If this is true then the final database will map some IPv6 ranges to the IPv4 range. These ranges are: =over 8 =item * ::ffff:0:0/96 This is the IPv4-mapped IPv6 range =item * 2001::/32 This is the Teredo range. Note that lookups for Teredo ranges will find the Teredo server's IPv4 address, not the client's IPv4. =item * 2002::/16 This is the 6to4 range =back When aliasing is enabled, insertions into the aliased locations will throw an exception. Inserting a network containing them does not throw an exception, but no information will be stored for the aliased locations. To insert an IPv4 address, insert it using IPv4 notation or insert directly into ::/96. Aliased nodes are I followed when merging nodes. Only merges into the original IPv4 location, ::/96, will be followed. This parameter is optional. It defaults to false. =item * remove_reserved_networks If this is true, reserved networks may not be inserted. Attempts to insert these networks or any inside them will be silently ignored. Inserting a network containing them does not throw an exception, but no information will be stored for the reserved sections. Reserved networks that are globally routable to an individual device, such as Teredo, may still be added. This parameter is optional. It defaults to true. =back =head2 $tree->insert_network( $network, $data, $additional_args ) This method expects two parameters. The first is a network in CIDR notation. The second can be any Perl data structure (except a coderef, glob, or filehandle). The C<$data> payload is encoded according to the L. The short overview is that anything that can be encoded in JSON can be stored in an MMDB file. It can also handle unsigned 64-bit and 128-bit integers if they are passed as L objects. C<$additional_args> is a hash reference containing additional arguments that change the behavior of the insert. The following arguments are supported: =over 3 =item * C When set, the tree's default merge strategy will be overridden for the insertion with this merge strategy. =item * C This make the merge strategy for the insert C. B =item * C This make the merge strategy for the insert C. B =back =head3 Insert Order, Merging, and Overwriting When C is I, the last insert "wins". This means that if you insert C<1.2.3.255/32> and then C<1.2.3.0/24>, the data for C<1.2.3.255/24> will overwrite the data you previously inserted for C<1.2.3.255/232>. On the other hand, if you insert C<1.2.3.255/32> last, then the tree will be split so that the C<1.2.3.0 - 1.2.3.254> range has different data than C<1.2.3.255>. In this scenario, if you want to make sure that no data is overwritten then you need to sort your input by network prefix length. When C is not I, then records will be merged based on the particular strategy. For instance, the C<1.2.3.255/32> network will end up with its data plus the data provided for the C<1.2.3.0/24> network, while C<1.2.3.0 - 1.2.3.254> will have the expected data. The merge strategy can be changed on a per-insert basis by using the C argument when inserting a network as discussed above. =head2 $tree->insert_range( $first_ip, $last_ip, $data, $additional_args ) This method is similar to C, except that it takes an IP range rather than a network. The first parameter is the first IP address in the range. The second is the last IP address in the range. The third is a Perl data structure containing the data to be inserted. The final parameter are additional arguments, as outlined for C. =head2 $tree->remove_network( $network ) This method removes the network from the database. It takes one parameter, the network in CIDR notation. =head2 $tree->write_tree($fh) Given a filehandle, this method writes the contents of the tree as a MaxMind DB database to that filehandle. =head2 $tree->iterate($object) This method iterates over the tree by calling methods on the passed object. The object must have at least one of the following three methods: C, C, C. The iteration is done in depth-first order, which means that it visits each network in order. Each method on the object is called with the following position parameters: =over 4 =item The node number as a 64-bit number. =item A boolean indicating whether or not this is the right or left record for the node. True for right, false for left. =item The first IP number in the node's network as a 128-bit number. =item The prefix length for the node's network. =item The first IP number in the record's network as a 128-bit number. =item The prefix length for the record's network. =back If the record is a data record, the final argument will be the Perl data structure associated with the record. The record's network is what matches with a given data structure for data records. For node (and alias) records, the final argument will be the number of the node that this record points to. For empty records, there are no additional arguments. =head2 $tree->freeze_tree($filename) Given a file name, this method freezes the tree to that file. Unlike the C method, this method does write out a MaxMind DB file. Instead, it writes out something that can be quickly thawed via the C<< MaxMind::DB::Writer::Tree->new_from_frozen_tree >> constructor. This is useful if you want to pass the in-memory representation of the tree between processes. =head2 $tree->ip_version() Returns the tree's IP version, as passed to the constructor. =head2 $tree->record_size() Returns the tree's record size, as passed to the constructor. =head2 $tree->merge_record_collisions() Returns a boolean indicating whether the tree will merge colliding records, as determined by the merge strategy. B =head2 $tree->merge_strategy() Returns the merge strategy used when two records collide. =head2 $tree->map_key_type_callback() Returns the callback used to determine the type of a map's values, as passed to the constructor. =head2 $tree->database_type() Returns the tree's database type, as passed to the constructor. =head2 $tree->languages() Returns the tree's languages, as passed to the constructor. =head2 $tree->description() Returns the tree's description hashref, as passed to the constructor. =head2 $tree->alias_ipv6_to_ipv4() Returns a boolean indicating whether the tree will alias some IPv6 ranges to their corresponding IPv4 ranges when the tree is written to disk. =head2 MaxMind::DB::Writer::Tree->new_from_frozen_tree() This method constructs a tree from a file containing a frozen tree. This method accepts the following parameters: =over 4 =item * filename The filename containing the frozen tree. This parameter is required. =item * map_key_type_callback This is a subroutine reference that is called in order to determine how to store each value in a map (hash) data structure. See L below for more details. This needs to be passed because subroutine references cannot be reliably serialized and restored between processes. This parameter is required. =item * database_type Override the C<> of the frozen tree. This accepts a string of the same form as the C<> constructor. This parameter is optional. =item * description Override the C<> of the frozen tree. This accepts a hashref of the same form as the C<> constructor. This parameter is optional. =item * merge_strategy Override the C<> setting for the frozen tree. This parameter is optional. =back =head2 Caveat for Freeze/Thaw The frozen tree is more or less the raw C data structures written to disk. As such, it is very much not portable, and your ability to thaw a tree on a machine not identical to the one on which it was written is not guaranteed. In addition, there is no guarantee that the freeze/thaw format will be stable across different versions of this module. =head1 DATA TYPES The MaxMind DB file format is strongly typed. Because Perl is not strongly typed, you will need to explicitly specify the types for each piece of data. Currently, this class assumes that your top-level data structure for an IP address will always be a map (hash). You can then provide a C subroutine that will be called as the data is serialized. This callback is given a key name and is expected to return that key's data type. Let's use the following structure as an example: { names => { en => 'United States', es => 'Estados Unidos', }, population => 319_000_000, fizzle_factor => 65.7294, states => [ 'Alabama', 'Alaska', ... ], } Given this data structure, our C might look something like this: my %types = ( names => 'map', en => 'utf8_string', es => 'utf8_string', population => 'uint32', fizzle_factor => 'double', states => [ 'array', 'utf8_string' ], ); sub { my $key = shift; return $type{$key}; } If the callback returns C, the serialization code will throw an error. Note that for an array we return a 2 element arrayref where the first element is C<'array'> and the second element is the type of content in the array. The valid types are: =over 4 =item * utf8_string =item * uint16 =item * uint32 =item * uint64 =item * uint128 =item * int32 =item * double 64 bits of precision. =item * float 32 bits of precision. =item * boolean =item * map =item * array =back =head1 SUPPORT Bugs may be submitted through L. =head1 AUTHORS =over 4 =item * Olaf Alders =item * Greg Oschwald =item * Dave Rolsky =item * Mark Fowler =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2018 by MaxMind, Inc. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Tree.xs100644000000000000 2173313321164704 21357 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/lib/MaxMind/DB/Writer/* *INDENT-ON* */ #ifdef __cplusplus extern "C" { #endif #include "tree.h" #ifdef __cplusplus } #endif typedef struct perl_iterator_args_s { SV *empty_method; SV *node_method; SV *data_method; SV *receiver; } perl_iterator_args_s; MMDBW_tree_s *tree_from_self(SV *self) { /* This is a bit wrong since we're looking in the $self hash rather than calling a method. I couldn't get method calling to work. */ return *(MMDBW_tree_s **)SvPV_nolen( *(hv_fetchs((HV *)SvRV(self), "_tree", 0))); } void call_iteration_method(MMDBW_tree_s *tree, perl_iterator_args_s *args, SV *method, const uint64_t node_number, MMDBW_record_s *record, const uint128_t node_ip_num, const uint8_t node_prefix_length, const uint128_t record_ip_num, const uint8_t record_prefix_length, const bool is_right) { dSP; ENTER; SAVETMPS; int stack_size = MMDBW_RECORD_TYPE_EMPTY == record->type || MMDBW_RECORD_TYPE_FIXED_EMPTY == record->type ? 7 : 8; PUSHMARK(SP); EXTEND(SP, stack_size); PUSHs((SV *)args->receiver); mPUSHs(newSVu64(node_number)); mPUSHi((int)is_right); mPUSHs(newSVu128(node_ip_num)); mPUSHi(node_prefix_length); mPUSHs(newSVu128(record_ip_num)); mPUSHi(record_prefix_length); if (MMDBW_RECORD_TYPE_DATA == record->type) { mPUSHs(newSVsv(data_for_key(tree, record->value.key))); } else if (MMDBW_RECORD_TYPE_NODE == record->type || MMDBW_RECORD_TYPE_FIXED_NODE == record->type || MMDBW_RECORD_TYPE_ALIAS == record->type) { mPUSHi(record->value.node->number); } PUTBACK; int count = call_sv(method, G_VOID); SPAGAIN; if (count != 0) { croak("Expected no items back from ->%s() call", SvPV_nolen(method)); } PUTBACK; FREETMPS; LEAVE; return; } SV *method_for_record_type(perl_iterator_args_s *args, const MMDBW_record_type record_type) { switch (record_type) { case MMDBW_RECORD_TYPE_EMPTY: case MMDBW_RECORD_TYPE_FIXED_EMPTY: return args->empty_method; break; case MMDBW_RECORD_TYPE_DATA: return args->data_method; break; case MMDBW_RECORD_TYPE_NODE: case MMDBW_RECORD_TYPE_FIXED_NODE: case MMDBW_RECORD_TYPE_ALIAS: return args->node_method; break; } // This croak is probably okay. It should not happen unless we're adding a // new record type and missed this spot. croak("unexpected record type"); return NULL; } void call_perl_object(MMDBW_tree_s *tree, MMDBW_node_s *node, const uint128_t node_ip_num, const uint8_t node_prefix_length, void *void_args) { perl_iterator_args_s *args = (perl_iterator_args_s *)void_args; SV *left_method = method_for_record_type(args, node->left_record.type); if (NULL != left_method) { call_iteration_method(tree, args, left_method, node->number, &(node->left_record), node_ip_num, node_prefix_length, node_ip_num, node_prefix_length + 1, false); } SV *right_method = method_for_record_type(args, node->right_record.type); if (NULL != right_method) { call_iteration_method( tree, args, right_method, node->number, &(node->right_record), node_ip_num, node_prefix_length, flip_network_bit(tree, node_ip_num, node_prefix_length), node_prefix_length + 1, true); } return; } /* It'd be nice to return the CV instead but there's no exposed API for * calling a CV directly. */ SV *maybe_method(HV *package, const char *const method) { GV *gv = gv_fetchmethod_autoload(package, method, 1); if (NULL != gv) { CV *cv = GvCV(gv); if (NULL != cv) { return newRV_noinc((SV *)cv); } } return NULL; } // clang-format off /* XXX - it'd be nice to find a way to get the tree from the XS code so we * don't have to pass it in all over place - it'd also let us remove at least * a few shim methods on the Perl code. */ MODULE = MaxMind::DB::Writer::Tree PACKAGE = MaxMind::DB::Writer::Tree #include BOOT: PERL_MATH_INT128_LOAD_OR_CROAK; MMDBW_tree_s * _create_tree(ip_version, record_size, merge_strategy, alias_ipv6, remove_reserved_networks) uint8_t ip_version; uint8_t record_size; MMDBW_merge_strategy merge_strategy; bool alias_ipv6; bool remove_reserved_networks; CODE: RETVAL = new_tree(ip_version, record_size, merge_strategy, alias_ipv6, remove_reserved_networks); OUTPUT: RETVAL void _insert_network(self, ip_address, prefix_length, key, data, merge_strategy) SV *self; char *ip_address; uint8_t prefix_length; SV *key; SV *data; MMDBW_merge_strategy merge_strategy; CODE: MMDBW_tree_s *tree = tree_from_self(self); insert_network(tree, ip_address, prefix_length, key, data, merge_strategy); void _insert_range(self, start_ip_address, end_ip_address, key, data, merge_strategy) SV *self; char *start_ip_address; char *end_ip_address; SV *key; SV *data; MMDBW_merge_strategy merge_strategy; CODE: insert_range(tree_from_self(self), start_ip_address, end_ip_address, key, data, merge_strategy); void _remove_network(self, ip_address, prefix_length) SV *self; char *ip_address; uint8_t prefix_length; CODE: remove_network(tree_from_self(self), ip_address, prefix_length); void _write_search_tree(self, output, root_data_type, serializer) SV *self; SV *output; SV *root_data_type; SV *serializer; CODE: write_search_tree(tree_from_self(self), output, root_data_type, serializer); uint32_t node_count(self) SV * self; CODE: MMDBW_tree_s *tree = tree_from_self(self); assign_node_numbers(tree); if (tree->node_count > max_record_value(tree)) { croak("Node count of %u exceeds record size limit of %u bits", tree->node_count, tree->record_size); } RETVAL = tree->node_count; OUTPUT: RETVAL void iterate(self, object) SV *self; SV *object; CODE: MMDBW_tree_s *tree = tree_from_self(self); assign_node_numbers(tree); HV *package; /* It's a blessed object */ if (sv_isobject(object)) { package = SvSTASH(SvRV(object)); /* It's a package name */ } else if (SvPOK(object) && !SvROK(object)) { package = gv_stashsv(object, 0); } else { croak("The argument passed to iterate (%s) is not an object or class name", SvPV_nolen(object)); } perl_iterator_args_s args = { .empty_method = maybe_method(package, "process_empty_record"), .node_method = maybe_method(package, "process_node_record"), .data_method = maybe_method(package, "process_data_record"), .receiver = object }; if (!(NULL != args.empty_method || NULL != args.node_method || NULL != args.data_method)) { croak("The object or class passed to iterate must implement " "at least one method of process_empty_record, " "process_node_record, or process_data_record"); } start_iteration(tree, true, (void *)&args, &call_perl_object); SV * lookup_ip_address(self, address) SV *self; char *address; CODE: RETVAL = lookup_ip_address(tree_from_self(self), address); OUTPUT: RETVAL void _freeze_tree(self, filename, frozen_params, frozen_params_size) SV *self; char *filename; char *frozen_params; int frozen_params_size; CODE: freeze_tree(tree_from_self(self), filename, frozen_params, frozen_params_size); MMDBW_tree_s * _thaw_tree(filename, initial_offset, ip_version, record_size, merge_strategy, alias_ipv6, remove_reserved_networks) char *filename; int initial_offset; int ip_version; int record_size; MMDBW_merge_strategy merge_strategy; bool alias_ipv6; bool remove_reserved_networks; CODE: RETVAL = thaw_tree(filename, initial_offset, ip_version, record_size, merge_strategy, alias_ipv6, remove_reserved_networks); OUTPUT: RETVAL void _free_tree(self) SV *self; CODE: free_tree(tree_from_self(self)); Util.pm100644000000000000 234713321164704 21337 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/lib/MaxMind/DB/Writerpackage MaxMind::DB::Writer::Util; use strict; use warnings; our $VERSION = '0.300003'; use Digest::SHA1 qw( sha1_base64 ); use Encode qw( encode ); use Sereal::Encoder 3.002 qw( sereal_encode_with_object ); use Exporter qw( import ); our @EXPORT_OK = qw( key_for_data ); { # Although this mostly works fine when canonical and canonical_refs are # enabled, it is still somewhat broken. See: # # https://metacpan.org/pod/distribution/Sereal-Encoder/lib/Sereal/Encoder.pm#CANONICAL-REPRESENTATION # # The arrays in the example, for instance, would have distinct keys # despite being structurally equivalent. Requires Sereal 3.002. my $Encoder = Sereal::Encoder->new( { canonical => 1, canonical_refs => 1, } ); sub key_for_data { # We need to use sha1 because the Sereal structure has \0 bytes which # confuse the C code. As a bonus, this makes the keys smaller so they # take up less space. As an un-bonus, this makes the code a little # slower. my $key = ref $_[0] ? sereal_encode_with_object( $Encoder, $_[0] ) : encode( 'UTF-8', $_[0] ); return sha1_base64($key); } } 1; typemap100644000000000000 111013321164704 21451 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/lib/MaxMind/DB/WriterTYPEMAP MMDBW_tree_s * T_OPAQUE uint8_t T_UV uint32_t T_UV MMDBW_merge_strategy MMDBW_MERGE_STRATEGY_T INPUT MMDBW_MERGE_STRATEGY_T char* sv_text = SvPV_nolen($arg); $var = !strcmp(sv_text, \"toplevel\") ? MMDBW_MERGE_STRATEGY_TOPLEVEL : !strcmp(sv_text, \"recurse\") ? MMDBW_MERGE_STRATEGY_RECURSE : !strcmp(sv_text, \"add-only-if-parent-exists\") ? MMDBW_MERGE_STRATEGY_ADD_ONLY_IF_PARENT_EXISTS : !strcmp(sv_text, \"none\") ? MMDBW_MERGE_STRATEGY_NONE : MMDBW_MERGE_STRATEGY_UNKNOWN; DB000755000000000000 013321164704 17624 5ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/lib/Test/MaxMindWriter.pm100644000000000000 1726113321164704 21625 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/lib/Test/MaxMind/DBpackage Test::MaxMind::DB::Writer; use strict; use warnings; use Test::More; use Data::Printer; use File::Temp qw( tempdir ); use List::Util qw( all ); use MaxMind::DB::Writer::Tree; use Net::Works::Address; use Net::Works::Network; use Scalar::Util qw( blessed ); use Test::HexDifferences qw( eq_or_dump_diff ); use Exporter qw( import ); our @EXPORT_OK = qw( insert_for_type make_tree_from_pairs ranges_to_data test_iterator_sanity test_freeze_thaw test_freeze_thaw_optional_params test_tree ); sub test_tree { my $insert_pairs = shift; my $expect_pairs = shift; my $desc = shift; my $args = shift; my $skip_dne_tests = shift; for my $type (qw( network range )) { subtest "$desc - insert_$type " => sub { my $tree = make_tree_from_pairs( $type, $insert_pairs, $args ); _test_expected_data( $tree, $expect_pairs, $desc ); return if $skip_dne_tests; for my $raw (qw( 1.1.1.33 8.9.10.11 ffff::1 )) { my $address = Net::Works::Address->new_from_string( string => $raw, version => ( $raw =~ /::/ ? 6 : 4 ), ); is( $tree->lookup_ip_address($address), undef, "The address $address is not in the tree - $desc" ); } }; } } sub make_tree_from_pairs { my $type = shift; my $pairs = shift; my $args = shift; my $tree = MaxMind::DB::Writer::Tree->new( ip_version => ( $pairs->[0][0] =~ /::/ ? 6 : 4 ), record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test tree' }, map_key_type_callback => sub { }, %{ $args || {} }, ); for my $pair ( @{$pairs} ) { my ( $network, @insert_args ) = @{$pair}; insert_for_type( $tree, $type, $network, @insert_args ); } return $tree; } sub insert_for_type { my $tree = shift; my $type = shift; my $network = shift; my @insert_args = @_; if ( $type eq 'network' ) { $tree->insert_network( $network, @insert_args ); return; } $network = Net::Works::Network->new_from_string( string => $network ) unless blessed $network; $tree->insert_range( $network->first, $network->last, @insert_args ); } sub _test_expected_data { my $tree = shift; my $expect = shift; my $desc = shift; foreach my $pair ( @{$expect} ) { my ( $network, $data ) = @{$pair}; my $iter = $network->iterator(); while ( my $address = $iter->() ) { my $result = $tree->lookup_ip_address($address); is_deeply( $tree->lookup_ip_address($address), $data, "Got expected data for $address - $desc" ) or diag p $result; } } } { # We want to have a unique id as part of the data for various tests my $id = 0; sub ranges_to_data { my $insert_ranges = shift; my $expect_ranges = shift; my %ip_to_data; my @insert; for my $network ( map { Net::Works::Network->range_as_subnets( @{$_} ), } @{$insert_ranges} ) { my $data = { x => 'foo', id => $id, }; push @insert, [ $network, $data ]; my $iter = $network->iterator(); while ( my $ip = $iter->() ) { $ip_to_data{ $ip->as_string() } = $data; } $id++; } my @expect = ( map { [ $_, $ip_to_data{ $_->first()->as_string() } ] } ( map { Net::Works::Network->range_as_subnets( @{$_} ), } @{$expect_ranges} ) ); return \@insert, \@expect; } } sub test_iterator_sanity { my $iterator = shift; my $tree = shift; my $network_count = shift; my $desc = shift; ok( ( all { $_ == 1 } values %{ $iterator->{nodes} } ), "each node was visited exactly once - $desc" ); ok( ( all { $_ == 1 } values %{ $iterator->{records} } ), "each record was visited exactly once - $desc" ); ok( ( all { $_ == 2 } values %{ $iterator->{networks} } ), "each network was visited exactly twice (two records per node) - $desc" ); is( scalar values %{ $iterator->{records} }, $tree->node_count() * 2, "saw every record for every node in the tree - $desc" ); my @data_networks = map { $_->[0] } @{ $iterator->{data_records} }; is( scalar @data_networks, $network_count, "saw $network_count networks - $desc" ); is_deeply( [ map { $_->as_string() } @data_networks ], [ map { $_->as_string() } sort @data_networks ], "data nodes are seen in network order when iterating - $desc" ); my %first_ips; for my $network (@data_networks) { $first_ips{ $network->first()->as_string }++; } ok( ( all { $_ == 1 } values %first_ips ), "did not see two data records with the same network first IP address - $desc" ); } sub test_freeze_thaw { my $tree1 = shift; my $dir = tempdir( CLEANUP => 1 ); my $file = "$dir/frozen-tree"; $tree1->freeze_tree($file); my $tree2 = MaxMind::DB::Writer::Tree->new_from_frozen_tree( filename => $file, map_key_type_callback => $tree1->map_key_type_callback(), ); my $now = time(); $_->_set_build_epoch($now) for $tree1, $tree2; my $tree1_output; open my $fh, '>:raw', \$tree1_output or die $!; $tree1->write_tree($fh); close $fh or die $!; my $tree2_output; open $fh, '>:raw', \$tree2_output or die $!; $tree2->write_tree($fh); close $fh or die $!; eq_or_dump_diff( $tree1_output, $tree2_output, 'output for tree is the same after freeze/thaw' ); my @attrs = qw( _root_data_type alias_ipv6_to_ipv4 database_type description ip_version languages merge_strategy record_size ); for my $attr (@attrs) { is_deeply( $tree1->$attr(), $tree2->$attr(), "$attr remains the same across freeze/thaw" ); } return ( $tree1, $tree2 ); } sub test_freeze_thaw_optional_params { my $tree1 = shift; my $dir = tempdir( CLEANUP => 1 ); my $file = "$dir/frozen-tree-params"; $tree1->freeze_tree($file); my $description = { en => 'A tree in the forest' }; my $type = 'TreeDB'; my $merge_strategy = 'recurse'; my $record_size = 32; my $tree2 = MaxMind::DB::Writer::Tree->new_from_frozen_tree( filename => $file, map_key_type_callback => $tree1->map_key_type_callback(), description => $description, database_type => $type, merge_strategy => $merge_strategy, record_size => $record_size, ); is( $tree2->database_type, $type, 'type passed to constructor overrides frozen type' ); is_deeply( $tree2->description, $description, 'description passed to constructor overrides frozen description' ); is_deeply( $tree2->merge_strategy, $merge_strategy, 'merge_strategy passed to constructor overrides frozen merge_strategy' ); is_deeply( $tree2->record_size, $record_size, 'record_size passed to constructor overrides frozen record_size' ); } 1; Serializer.t100644000000000000 1167713321164704 22105 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writeruse strict; use warnings; use lib 't/lib'; use Test::MaxMind::DB::Common::Data qw( test_cases_for ); use Test::Bits; use Test::Fatal; use Test::More; use Math::Int128 qw( uint128 ); use MaxMind::DB::Writer::Serializer; my $strings = test_cases_for( 'utf8_string', skip_huge_strings => 1, ); { my $serializer = MaxMind::DB::Writer::Serializer->new( map_key_type_callback => sub { } ); for my $i ( 0, 2, 4, 6 ) { $serializer->store_data( utf8_string => $strings->[$i] ); } my $expect = [ map { @{ $strings->[$_] } } ( 1, 3, 5, 7 ) ]; bits_is( ${ $serializer->buffer() }, $expect, 'serializer contains all strings we stored' ); $serializer->store_data( utf8_string => $strings->[6] ); push @{$expect}, @{ $strings->[7] }; bits_is( ${ $serializer->buffer() }, $expect, 'serializer did not make a pointer to 3-byte string' ); } { my $serializer = MaxMind::DB::Writer::Serializer->new( map_key_type_callback => sub { } ); for my $i ( 4, 6, 8, 10 ) { $serializer->store_data( utf8_string => $strings->[$i] ); } my $expect = [ map { @{ $strings->[$_] } } ( 5, 7, 9, 11 ) ]; bits_is( ${ $serializer->buffer() }, $expect, 'serializer contains all strings we stored' ); $serializer->store_data( utf8_string => $strings->[8] ); push @{$expect}, ( 0b00100000, 0b00001000 ); bits_is( ${ $serializer->buffer() }, $expect, 'serializer contains pointer to large string instead of the string itself' ); } { my $uint16s = test_cases_for('uint16'); my $serializer = MaxMind::DB::Writer::Serializer->new( map_key_type_callback => sub { } ); for my $i ( 0, 2, 4, 6 ) { $serializer->store_data( uint16 => $uint16s->[$i] ); } my $expect = [ map { @{ $uint16s->[$_] } } ( 1, 3, 5, 7 ) ]; bits_is( ${ $serializer->buffer() }, $expect, 'serializer stored uint16s as expected' ); $serializer->store_data( uint16 => $uint16s->[2] ); push @{$expect}, @{ $uint16s->[3] }; bits_is( ${ $serializer->buffer() }, $expect, 'serializer does not create a pointer for a uint16' ); } { my $uint64s = test_cases_for('uint64'); my $serializer = MaxMind::DB::Writer::Serializer->new( map_key_type_callback => sub { } ); for my $i ( 0, 2, 4, 6 ) { $serializer->store_data( uint64 => $uint64s->[$i] ); } my $expect = [ map { @{ $uint64s->[$_] } } ( 1, 3, 5, 7 ) ]; bits_is( ${ $serializer->buffer() }, $expect, 'serializer stored uint64s as expected' ); $serializer->store_data( uint64 => $uint64s->[2] ); push @{$expect}, @{ $uint64s->[3] }; bits_is( ${ $serializer->buffer() }, $expect, 'serializer does not create a pointer for a uint64 that can be stored in one byte' ); } { my $uint128s = test_cases_for('uint128'); my $serializer = MaxMind::DB::Writer::Serializer->new( map_key_type_callback => sub { } ); for my $i ( 0, 2, 4, 6 ) { $serializer->store_data( uint128 => $uint128s->[$i] ); } my $expect = [ map { @{ $uint128s->[$_] } } ( 1, 3, 5, 7 ) ]; bits_is( ${ $serializer->buffer() }, $expect, 'serializer stored uint128s as expected' ); $serializer->store_data( uint128 => $uint128s->[2] ); push @{$expect}, @{ $uint128s->[3] }; bits_is( ${ $serializer->buffer() }, $expect, 'serializer does not create a pointer for a uint128 that can be stored in one byte' ); } { my $serializer = MaxMind::DB::Writer::Serializer->new( map_key_type_callback => sub { } ); my $int = uint128(0) - 1; $serializer->store_data( uint128 => $int ); my $expect = [ 0b00010000, 0b00000011, (0b11111111) x 16 ]; bits_is( ${ $serializer->buffer() }, $expect, 'serializer stored 16 byte uint128 as expected' ); $serializer->store_data( uint128 => $int ); push @{$expect}, ( 0b00100000, 0b00000000 ); bits_is( ${ $serializer->buffer() }, $expect, 'serializer stored pointer to 16 byte uint128 as expected' ); } { my $maps = test_cases_for('map'); my $serializer = MaxMind::DB::Writer::Serializer->new( map_key_type_callback => sub { ref $_[1] ? 'map' : 'utf8_string' } ); for my $i ( 0, 2, 4, 6 ) { $serializer->store_data( map => $maps->[$i] ); } my $expect = [ map { @{ $maps->[$_] } } ( 1, 3, 5, 7 ) ]; bits_is( ${ $serializer->buffer() }, $expect, 'serializer stored maps as expected' ); $serializer->store_data( map => $maps->[2] ); push @{$expect}, ( 0b00100000, 0b00000001 ); bits_is( ${ $serializer->buffer() }, $expect, 'serializer stored pointer to map as expected' ); } done_testing(); test-data000755000000000000 013321164704 16203 5ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/tgeolite2-sample.json100644000000000000 36341213321164704 22300 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/test-data[ [ "2001:218::/32", "JP" ], [ "2001:220::/32", "KR" ], [ "2001:230::/32", "KR" ], [ "2001:238::/32", "TW" ], [ "2001:240::/32", "JP" ], [ "2001:250::/31", "CN" ], [ "2001:252::/32", "CN" ], [ "2001:254::/32", "CN" ], [ "2001:256::/32", "CN" ], [ "2001:258::/32", "JP" ], [ "2001:260::/32", "JP" ], [ "2001:268::/32", "JP" ], [ "2001:270::/32", "KR" ], [ "2001:278::/32", "JP" ], [ "2001:280::/32", "KR" ], [ "2001:288::/32", "TW" ], [ "2001:290::/32", "KR" ], [ "2001:298::/32", "JP" ], [ "2001:2a0::/32", "JP" ], [ "2001:2a8::/32", "JP" ], [ "2001:2b0::/32", "KR" ], [ "2001:2b8::/32", "KR" ], [ "2001:2c0::/32", "JP" ], [ "2001:2c8::/32", "JP" ], [ "2001:2d8::/32", "KR" ], [ "2001:2e0::/32", "HK" ], [ "2001:2e8::/32", "JP" ], [ "2001:2f0::/32", "JP" ], [ "2001:2f8::/32", "JP" ], [ "2001:300::/32", "JP" ], [ "2001:308::/32", "JP" ], [ "2001:310::/32", "JP" ], [ "2001:318::/32", "JP" ], [ "2001:320::/32", "KR" ], [ "2001:328::/32", "MY" ], [ "2001:330::/32", "KR" ], [ "2001:338::/32", "JP" ], [ "2001:340::/32", "JP" ], [ "2001:348::/32", "JP" ], [ "2001:350::/32", "JP" ], [ "2001:358::/32", "JP" ], [ "2001:360::/32", "AU" ], [ "2001:368::/32", "JP" ], [ "2001:370::/32", "JP" ], [ "2001:378::/32", "KR" ], [ "2001:380::/32", "JP" ], [ "2001:388::/32", "AU" ], [ "2001:390::/32", "KR" ], [ "2001:398::/32", "JP" ], [ "2001:3a0::/32", "JP" ], [ "2001:3a8::/32", "KR" ], [ "2001:3b0::/32", "JP" ], [ "2001:3b8::/32", "JP" ], [ "2001:3c0::/35", "JP" ], [ "2001:3c8::/32", "TH" ], [ "2001:3d0::/32", "JP" ], [ "2001:3d8::/32", "JP" ], [ "2001:3e0::/32", "JP" ], [ "2001:3e8::/32", "JP" ], [ "2001:400::/32", "US" ], [ "2001:408::/32", "US" ], [ "2001:410::/32", "CA" ], [ "2001:418::/32", "US" ], [ "2001:420::/32", "US" ], [ "2001:428::/32", "US" ], [ "2001:430::/32", "US" ], [ "2001:438::/32", "US" ], [ "2001:440::/32", "US" ], [ "2001:448::/32", "MX" ], [ "2001:450::/32", "US" ], [ "2001:458::/32", "US" ], [ "2001:460::/32", "US" ], [ "2001:468::/32", "US" ], [ "2001:470::/32", "US" ], [ "2001:478::/32", "KN" ], [ "2001:480::/32", "US" ], [ "2001:490::/32", "US" ], [ "2001:4a0::/32", "US" ], [ "2001:4b0::/32", "US" ], [ "2001:4b8::/32", "US" ], [ "2001:4c0::/32", "CA" ], [ "2001:4c8::/32", "CA" ], [ "2001:4d0::/32", "US" ], [ "2001:4e0::/32", "US" ], [ "2001:4e8::/32", "CA" ], [ "2001:4f0::/32", "US" ], [ "2001:4f8::/32", "US" ], [ "2001:500:1::/48", "US" ], [ "2001:500:2::/47", "US" ], [ "2001:500:4::/48", "US" ], [ "2001:500:6::/47", "CA" ], [ "2001:500:8::/45", "CA" ], [ "2001:500:10::/48", "PR" ], [ "2001:500:11::/48", "US" ], [ "2001:500:12::/47", "US" ], [ "2001:500:14::/47", "US" ], [ "2001:500:16::/47", "CA" ], [ "2001:500:18::/45", "CA" ], [ "2001:500:20::/45", "CA" ], [ "2001:500:28::/46", "CA" ], [ "2001:500:2c::/48", "CA" ], [ "2001:500:2d::/48", "US" ], [ "2001:500:2e::/47", "US" ], [ "2001:500:30::/47", "US" ], [ "2001:500:40::/44", "CA" ], [ "2001:500:50::/46", "CA" ], [ "2001:500:54::/47", "CA" ], [ "2001:500:56::/48", "CA" ], [ "2001:500:60::/44", "US" ], [ "2001:500:70::/45", "US" ], [ "2001:500:78::/46", "US" ], [ "2001:500:7c::/47", "US" ], [ "2001:500:80::/46", "CA" ], [ "2001:500:84::/46", "US" ], [ "2001:500:88::/47", "US" ], [ "2001:500:8c::/46", "US" ], [ "2001:500:90::/45", "US" ], [ "2001:500:98::/47", "US" ], [ "2001:500:9a::/48", "US" ], [ "2001:500:9c::/46", "US" ], [ "2001:500:a0::/45", "CA" ], [ "2001:500:a8::/48", "US" ], [ "2001:500:c0::/43", "CA" ], [ "2001:500:e0::/44", "CA" ], [ "2001:500:f0::/48", "US" ], [ "2001:500:f1::/48", "CA" ], [ "2001:500:100::/45", "CA" ], [ "2001:500:108::/47", "CA" ], [ "2001:500:3e5::/48", "US" ], [ "2001:500:30ff::/48", "US" ], [ "2001:500:3682::/48", "US" ], [ "2001:500:4431::/48", "US" ], [ "2001:500:7967::/48", "US" ], [ "2001:500:856e::/48", "US" ], [ "2001:500:d937::/48", "US" ], [ "2001:500:ed30::/48", "US" ], [ "2001:501:8a29::/48", "US" ], [ "2001:501:973c::/48", "US" ], [ "2001:501:b1f9::/48", "US" ], [ "2001:502:8cc::/48", "US" ], [ "2001:502:100e::/48", "US" ], [ "2001:502:1ca1::/48", "US" ], [ "2001:502:2eda::/48", "US" ], [ "2001:502:4612::/48", "US" ], [ "2001:502:63bd::/48", "US" ], [ "2001:502:7094::/48", "US" ], [ "2001:502:7a71::/48", "US" ], [ "2001:502:8c25::/48", "US" ], [ "2001:502:ad09::/48", "US" ], [ "2001:502:be98::/48", "US" ], [ "2001:502:cbe4::/48", "US" ], [ "2001:502:cfb5::/48", "US" ], [ "2001:502:d399::/48", "US" ], [ "2001:502:f3ff::/48", "US" ], [ "2001:503:c27::/48", "US" ], [ "2001:503:d2d::/48", "US" ], [ "2001:503:231d::/48", "US" ], [ "2001:503:3227::/48", "US" ], [ "2001:503:39c1::/48", "US" ], [ "2001:503:4872::/48", "US" ], [ "2001:503:5419::/48", "US" ], [ "2001:503:5ae2::/48", "US" ], [ "2001:503:6810::/48", "US" ], [ "2001:503:7bbb::/48", "US" ], [ "2001:503:7bbf::/48", "US" ], [ "2001:503:8028::/48", "US" ], [ "2001:503:83eb::/48", "US" ], [ "2001:503:91ef::/48", "US" ], [ "2001:503:a124::/48", "US" ], [ "2001:503:a83e::/48", "US" ], [ "2001:503:ba3e::/48", "US" ], [ "2001:503:bfb0::/48", "US" ], [ "2001:503:c779::/48", "US" ], [ "2001:503:cc2c::/48", "US" ], [ "2001:503:d1ae::/48", "US" ], [ "2001:503:d414::/48", "US" ], [ "2001:503:e239::/48", "US" ], [ "2001:503:e8ef::/48", "US" ], [ "2001:503:eea3::/48", "US" ], [ "2001:503:f189::/48", "US" ], [ "2001:503:f261::/48", "US" ], [ "2001:503:f3da::/48", "US" ], [ "2001:503:ff39::/48", "US" ], [ "2001:504::/44", "US" ], [ "2001:504:10::/46", "US" ], [ "2001:504:15::/48", "CA" ], [ "2001:504:16::/47", "US" ], [ "2001:504:18::/47", "US" ], [ "2001:504:1a::/48", "CA" ], [ "2001:504:1b::/48", "US" ], [ "2001:504:1c::/48", "US" ], [ "2001:504:1d::/48", "PR" ], [ "2001:504:20::/46", "CA" ], [ "2001:504:24::/48", "US" ], [ "2001:504:25::/48", "CA" ], [ "2001:504:26::/48", "CA" ], [ "2001:504:27::/48", "US" ], [ "2001:504:28::/47", "US" ], [ "2001:504:2a::/48", "US" ], [ "2001:504:2b::/48", "CA" ], [ "2001:504:2c::/47", "CA" ], [ "2001:504:2e::/48", "US" ], [ "2001:504:2f::/48", "CA" ], [ "2001:506::/47", "US" ], [ "2001:506:8::/48", "US" ], [ "2001:506:20::/48", "CA" ], [ "2001:506:28::/48", "US" ], [ "2001:506:100::/48", "US" ], [ "2001:506:1000::/36", "US" ], [ "2001:506:2000::/36", "US" ], [ "2001:506:4000::/34", "US" ], [ "2001:508::/32", "BM" ], [ "2001:510::/32", "CA" ], [ "2001:518::/32", "US" ], [ "2001:520::/32", "US" ], [ "2001:528::/32", "US" ], [ "2001:530::/32", "US" ], [ "2001:538::/32", "US" ], [ "2001:540::/32", "US" ], [ "2001:548::/32", "US" ], [ "2001:550::/32", "US" ], [ "2001:558::/29", "US" ], [ "2001:560::/32", "US" ], [ "2001:568::/29", "CA" ], [ "2001:570::/32", "US" ], [ "2001:578::/30", "US" ], [ "2001:580::/32", "US" ], [ "2001:590::/32", "US" ], [ "2001:598::/32", "CA" ], [ "2001:5a0::/32", "CA" ], [ "2001:5a8::/32", "US" ], [ "2001:5b0::/32", "US" ], [ "2001:5b8::/32", "US" ], [ "2001:5c0::/32", "CA" ], [ "2001:5c8::/32", "US" ], [ "2001:5d0::/32", "US" ], [ "2001:5d8::/32", "US" ], [ "2001:5e0::/32", "US" ], [ "2001:5e8::/32", "US" ], [ "2001:5f0::/32", "US" ], [ "2001:5f8::/32", "US" ], [ "2001:600::/32", "EU" ], [ "2001:608::/32", "DE" ], [ "2001:610::/32", "NL" ], [ "2001:618::/32", "CH" ], [ "2001:620::/32", "CH" ], [ "2001:628::/29", "AT" ], [ "2001:630::/32", "GB" ], [ "2001:638::/32", "DE" ], [ "2001:640::/32", "RU" ], [ "2001:648::/32", "GR" ], [ "2001:650::/29", "DE" ], [ "2001:658::/32", "DE" ], [ "2001:660::/29", "FR" ], [ "2001:668::/29", "DE" ], [ "2001:670::/30", "FI" ], [ "2001:678:1::/48", "CZ" ], [ "2001:678:2::/48", "DE" ], [ "2001:678:3::/48", "CH" ], [ "2001:678:4::/47", "GB" ], [ "2001:678:6::/48", "LT" ], [ "2001:678:7::/48", "GR" ], [ "2001:678:8::/48", "NL" ], [ "2001:678:9::/48", "BE" ], [ "2001:678:a::/48", "BE" ], [ "2001:678:b::/48", "LV" ], [ "2001:678:c::/48", "FR" ], [ "2001:678:d::/48", "AT" ], [ "2001:678:e::/48", "DE" ], [ "2001:678:f::/48", "CZ" ], [ "2001:678:10::/47", "CZ" ], [ "2001:678:12::/48", "IT" ], [ "2001:678:13::/48", "RU" ], [ "2001:678:14::/46", "RU" ], [ "2001:678:18::/48", "RU" ], [ "2001:678:19::/48", "LT" ], [ "2001:678:1a::/48", "DK" ], [ "2001:678:1b::/48", "LU" ], [ "2001:678:1c::/48", "AT" ], [ "2001:678:20::/48", "AT" ], [ "2001:678:24::/48", "AT" ], [ "2001:678:28::/48", "SM" ], [ "2001:678:2c::/48", "NL" ], [ "2001:678:30::/48", "NL" ], [ "2001:678:34::/48", "NL" ], [ "2001:678:38::/48", "NL" ], [ "2001:678:3c::/48", "BG" ], [ "2001:678:40::/48", "ES" ], [ "2001:678:44::/48", "ES" ], [ "2001:678:48::/48", "ES" ], [ "2001:678:4c::/48", "FR" ], [ "2001:678:50::/48", "EU" ], [ "2001:678:54::/48", "EU" ], [ "2001:678:58::/48", "EU" ], [ "2001:678:5c::/48", "EU" ], [ "2001:678:60::/48", "LU" ], [ "2001:678:64::/48", "BE" ], [ "2001:678:68::/48", "BE" ], [ "2001:678:6c::/48", "BE" ], [ "2001:678:70::/48", "SK" ], [ "2001:678:74::/48", "DK" ], [ "2001:678:78::/48", "DK" ], [ "2001:678:7c::/48", "LV" ], [ "2001:678:80::/48", "LV" ], [ "2001:678:84::/48", "LV" ], [ "2001:678:88::/48", "LT" ], [ "2001:678:8c::/48", "LT" ], [ "2001:678:90::/48", "SK" ], [ "2001:678:94::/48", "EE" ], [ "2001:67c::/48", "IE" ], [ "2001:67c:4::/48", "DE" ], [ "2001:67c:8::/48", "CH" ], [ "2001:67c:c::/48", "PL" ], [ "2001:67c:10::/48", "RO" ], [ "2001:67c:14::/48", "DE" ], [ "2001:67c:18::/48", "NL" ], [ "2001:67c:1c::/48", "SE" ], [ "2001:67c:20::/48", "IE" ], [ "2001:67c:24::/48", "DE" ], [ "2001:67c:2c::/48", "NL" ], [ "2001:67c:30::/48", "RO" ], [ "2001:67c:34::/48", "NL" ], [ "2001:67c:38::/48", "NL" ], [ "2001:67c:40::/48", "BE" ], [ "2001:67c:44::/48", "RO" ], [ "2001:67c:4c::/48", "AT" ], [ "2001:67c:50::/48", "NL" ], [ "2001:67c:54::/48", "NL" ], [ "2001:67c:58::/48", "SI" ], [ "2001:67c:5c::/48", "BE" ], [ "2001:67c:60::/48", "NL" ], [ "2001:67c:64::/48", "NL" ], [ "2001:67c:68::/48", "CZ" ], [ "2001:67c:6c::/48", "IS" ], [ "2001:67c:70::/48", "FR" ], [ "2001:67c:74::/48", "NL" ], [ "2001:67c:78::/48", "RO" ], [ "2001:67c:84::/48", "CZ" ], [ "2001:67c:88::/48", "CH" ], [ "2001:67c:8c::/48", "RU" ], [ "2001:67c:90::/48", "GB" ], [ "2001:67c:94::/48", "CH" ], [ "2001:67c:98::/48", "CH" ], [ "2001:67c:9c::/48", "BE" ], [ "2001:67c:a0::/48", "GB" ], [ "2001:67c:a4::/48", "NO" ], [ "2001:67c:a8::/48", "DE" ], [ "2001:67c:ac::/48", "AT" ], [ "2001:67c:b0::/48", "NL" ], [ "2001:67c:b4::/48", "GB" ], [ "2001:67c:b8::/48", "DK" ], [ "2001:67c:bc::/48", "EE" ], [ "2001:67c:c4::/48", "FR" ], [ "2001:67c:c8::/48", "CH" ], [ "2001:67c:cc::/48", "DE" ], [ "2001:67c:d0::/48", "AT" ], [ "2001:67c:d4::/48", "GB" ], [ "2001:67c:d8::/48", "SE" ], [ "2001:67c:dc::/48", "SE" ], [ "2001:67c:e0::/48", "NL" ], [ "2001:67c:e4::/48", "AT" ], [ "2001:67c:e8::/48", "CZ" ], [ "2001:67c:ec::/48", "FR" ], [ "2001:67c:f0::/48", "NL" ], [ "2001:67c:f4::/48", "RU" ], [ "2001:67c:f8::/48", "UA" ], [ "2001:67c:fc::/48", "DE" ], [ "2001:67c:100::/48", "CH" ], [ "2001:67c:108::/48", "NL" ], [ "2001:67c:10c::/48", "GB" ], [ "2001:67c:110::/48", "FI" ], [ "2001:67c:114::/48", "NL" ], [ "2001:67c:118::/48", "GB" ], [ "2001:67c:11c::/48", "PL" ], [ "2001:67c:120::/48", "BE" ], [ "2001:67c:124::/48", "SI" ], [ "2001:67c:128::/48", "FR" ], [ "2001:67c:12c::/48", "FI" ], [ "2001:67c:130::/48", "SA" ], [ "2001:67c:134::/48", "DE" ], [ "2001:67c:138::/48", "DE" ], [ "2001:67c:13c::/48", "DE" ], [ "2001:67c:140::/48", "DE" ], [ "2001:67c:144::/48", "GB" ], [ "2001:67c:148::/48", "AT" ], [ "2001:67c:14c::/47", "DE" ], [ "2001:67c:154::/48", "RO" ], [ "2001:67c:158::/48", "DK" ], [ "2001:67c:15c::/48", "FI" ], [ "2001:67c:160::/48", "CH" ], [ "2001:67c:164::/48", "FI" ], [ "2001:67c:168::/48", "CH" ], [ "2001:67c:170::/48", "CH" ], [ "2001:67c:174::/48", "NL" ], [ "2001:67c:178::/48", "AT" ], [ "2001:67c:17c::/48", "AT" ], [ "2001:67c:180::/48", "AT" ], [ "2001:67c:184::/48", "DK" ], [ "2001:67c:188::/48", "GB" ], [ "2001:67c:18c::/48", "RU" ], [ "2001:67c:190::/48", "SE" ], [ "2001:67c:194::/48", "DE" ], [ "2001:67c:19c::/48", "SE" ], [ "2001:67c:1a0::/48", "SI" ], [ "2001:67c:1a4::/48", "NL" ], [ "2001:67c:1a8::/48", "NL" ], [ "2001:67c:1ac::/48", "DE" ], [ "2001:67c:1b0::/48", "PL" ], [ "2001:67c:1b4::/48", "PL" ], [ "2001:67c:1b8::/48", "GB" ], [ "2001:67c:1bc::/48", "AT" ], [ "2001:67c:1c0::/48", "GB" ], [ "2001:67c:1c4::/48", "GB" ], [ "2001:67c:1c8::/48", "PL" ], [ "2001:67c:1cc::/48", "BE" ], [ "2001:67c:1d0::/48", "AT" ], [ "2001:67c:1d4::/48", "NL" ], [ "2001:67c:1d8::/48", "DE" ], [ "2001:67c:1dc::/48", "GB" ], [ "2001:67c:1e0::/48", "RO" ], [ "2001:67c:1e4::/48", "SE" ], [ "2001:67c:1e8::/48", "NL" ], [ "2001:67c:1ec::/48", "NO" ], [ "2001:67c:1f0::/48", "NL" ], [ "2001:67c:1f4::/48", "DK" ], [ "2001:67c:1f8::/48", "DE" ], [ "2001:67c:1fc::/48", "SI" ], [ "2001:67c:200::/48", "FR" ], [ "2001:67c:204::/48", "CH" ], [ "2001:67c:208::/48", "DE" ], [ "2001:67c:20c::/48", "NL" ], [ "2001:67c:210::/48", "AT" ], [ "2001:67c:214::/48", "DE" ], [ "2001:67c:218::/48", "LT" ], [ "2001:67c:21c::/48", "AM" ], [ "2001:67c:220::/48", "DE" ], [ "2001:67c:224::/48", "FI" ], [ "2001:67c:228::/48", "NO" ], [ "2001:67c:22c::/48", "GB" ], [ "2001:67c:230::/48", "NO" ], [ "2001:67c:234::/48", "CH" ], [ "2001:67c:238::/48", "DK" ], [ "2001:67c:23c::/48", "CH" ], [ "2001:67c:240::/48", "CH" ], [ "2001:67c:244::/48", "CH" ], [ "2001:67c:248::/48", "AT" ], [ "2001:67c:24c::/48", "PL" ], [ "2001:67c:250::/48", "DE" ], [ "2001:67c:254::/48", "DE" ], [ "2001:67c:258::/48", "UA" ], [ "2001:67c:25c::/48", "FI" ], [ "2001:67c:260::/48", "CH" ], [ "2001:67c:264::/48", "AT" ], [ "2001:67c:268::/48", "CH" ], [ "2001:67c:26c::/48", "CZ" ], [ "2001:67c:270::/48", "NL" ], [ "2001:67c:274::/48", "SE" ], [ "2001:67c:278::/48", "CZ" ], [ "2001:67c:27c::/48", "AT" ], [ "2001:67c:280::/48", "CZ" ], [ "2001:67c:284::/48", "CZ" ], [ "2001:67c:288::/48", "FR" ], [ "2001:67c:28c::/48", "NL" ], [ "2001:67c:294::/48", "NL" ], [ "2001:67c:298::/48", "SE" ], [ "2001:67c:29c::/48", "IT" ], [ "2001:67c:2a0::/48", "SE" ], [ "2001:67c:2a4::/48", "DE" ], [ "2001:67c:2a8::/48", "NO" ], [ "2001:67c:2ac::/48", "DE" ], [ "2001:67c:2b0::/48", "FI" ], [ "2001:67c:2b8::/48", "AT" ], [ "2001:67c:2bc::/48", "DE" ], [ "2001:67c:2c0::/48", "AT" ], [ "2001:67c:2c4::/48", "CH" ], [ "2001:67c:2c8::/48", "NL" ], [ "2001:67c:2cc::/48", "DE" ], [ "2001:67c:2d0::/48", "NL" ], [ "2001:67c:2d4::/48", "NL" ], [ "2001:67c:2d8::/48", "AT" ], [ "2001:67c:2dc::/48", "NO" ], [ "2001:67c:2e0::/48", "PL" ], [ "2001:67c:2e4::/48", "NL" ], [ "2001:67c:2e8::/48", "NL" ], [ "2001:67c:2ec::/48", "NL" ], [ "2001:67c:2f0::/48", "SI" ], [ "2001:67c:2f4::/48", "LU" ], [ "2001:67c:2f8::/48", "CH" ], [ "2001:67c:2fc::/48", "DE" ], [ "2001:67c:300::/48", "SI" ], [ "2001:67c:304::/48", "BE" ], [ "2001:67c:308::/48", "DE" ], [ "2001:67c:30c::/48", "DE" ], [ "2001:67c:310::/48", "CY" ], [ "2001:67c:314::/48", "BE" ], [ "2001:67c:318::/48", "DK" ], [ "2001:67c:31c::/48", "DE" ], [ "2001:67c:324::/48", "NO" ], [ "2001:67c:328::/48", "DK" ], [ "2001:67c:32c::/48", "EE" ], [ "2001:67c:330::/48", "SE" ], [ "2001:67c:334::/48", "NL" ], [ "2001:67c:338::/48", "IE" ], [ "2001:67c:33c::/48", "CH" ], [ "2001:67c:340::/48", "CH" ], [ "2001:67c:344::/48", "BE" ], [ "2001:67c:348::/48", "GB" ], [ "2001:67c:34c::/48", "DE" ], [ "2001:67c:350::/48", "AT" ], [ "2001:67c:354::/48", "FR" ], [ "2001:67c:358::/48", "CH" ], [ "2001:67c:35c::/48", "SE" ], [ "2001:67c:360::/48", "RU" ], [ "2001:67c:364::/48", "CH" ], [ "2001:67c:368::/48", "LV" ], [ "2001:67c:36c::/48", "CH" ], [ "2001:67c:370::/48", "CH" ], [ "2001:67c:374::/48", "DE" ], [ "2001:67c:37c::/48", "CH" ], [ "2001:67c:380::/48", "CZ" ], [ "2001:67c:384::/48", "DE" ], [ "2001:67c:388::/48", "DE" ], [ "2001:67c:38c::/48", "GB" ], [ "2001:67c:390::/48", "NL" ], [ "2001:67c:394::/48", "SE" ], [ "2001:67c:398::/48", "NO" ], [ "2001:67c:39c::/48", "DE" ], [ "2001:67c:3a0::/48", "NL" ], [ "2001:67c:3a4::/48", "NL" ], [ "2001:67c:3a8::/48", "DE" ], [ "2001:67c:3ac::/48", "RS" ], [ "2001:67c:3b0::/48", "FR" ], [ "2001:67c:3b4::/48", "CZ" ], [ "2001:67c:3b8::/48", "IE" ], [ "2001:67c:3bc::/48", "DK" ], [ "2001:67c:3c0::/48", "DK" ], [ "2001:67c:3c4::/48", "RU" ], [ "2001:67c:3c8::/48", "EE" ], [ "2001:67c:3cc::/48", "SE" ], [ "2001:67c:3d0::/48", "NL" ], [ "2001:67c:3d4::/48", "CZ" ], [ "2001:67c:3d8::/48", "GB" ], [ "2001:67c:3dc::/48", "GB" ], [ "2001:67c:3e0::/48", "GB" ], [ "2001:67c:3e4::/48", "GB" ], [ "2001:67c:3e8::/47", "SA" ], [ "2001:67c:3f0::/48", "GB" ], [ "2001:67c:3f4::/48", "HR" ], [ "2001:67c:3f8::/48", "SI" ], [ "2001:67c:3fc::/48", "AT" ], [ "2001:67c:1000::/47", "SE" ], [ "2001:67c:1008::/47", "RU" ], [ "2001:67c:1010::/47", "SE" ], [ "2001:67c:1018::/47", "DE" ], [ "2001:67c:1020::/47", "AT" ], [ "2001:67c:1028::/47", "CH" ], [ "2001:67c:1030::/48", "FR" ], [ "2001:67c:1034::/48", "RO" ], [ "2001:67c:1038::/48", "RO" ], [ "2001:67c:103c::/48", "CZ" ], [ "2001:67c:1040::/48", "PL" ], [ "2001:67c:1044::/48", "CH" ], [ "2001:67c:1048::/48", "GB" ], [ "2001:67c:104c::/48", "NL" ], [ "2001:67c:1050::/48", "DE" ], [ "2001:67c:1054::/48", "DE" ], [ "2001:67c:1058::/48", "NL" ], [ "2001:67c:105c::/48", "GB" ], [ "2001:67c:1060::/48", "LU" ], [ "2001:67c:1064::/48", "NL" ], [ "2001:67c:1068::/48", "DK" ], [ "2001:67c:106c::/48", "GB" ], [ "2001:67c:1070::/47", "NO" ], [ "2001:67c:1078::/48", "AT" ], [ "2001:67c:107c::/48", "SE" ], [ "2001:67c:1080::/48", "NL" ], [ "2001:67c:1084::/48", "SE" ], [ "2001:67c:1090::/48", "CH" ], [ "2001:67c:1098::/48", "GB" ], [ "2001:67c:109c::/48", "GB" ], [ "2001:67c:10a0::/48", "GB" ], [ "2001:67c:10a4::/48", "FI" ], [ "2001:67c:10a8::/47", "DE" ], [ "2001:67c:10b0::/48", "RU" ], [ "2001:67c:10b4::/48", "PL" ], [ "2001:67c:10b8::/48", "AT" ], [ "2001:67c:10bc::/48", "AT" ], [ "2001:67c:10c0::/48", "SE" ], [ "2001:67c:10c4::/48", "GB" ], [ "2001:67c:10c8::/48", "SE" ], [ "2001:67c:10cc::/48", "SE" ], [ "2001:67c:10d0::/48", "SE" ], [ "2001:67c:10d4::/48", "GB" ], [ "2001:67c:10d8::/48", "GB" ], [ "2001:67c:10dc::/48", "SE" ], [ "2001:67c:10e0::/48", "AT" ], [ "2001:67c:10e4::/48", "SE" ], [ "2001:67c:10e8::/48", "CZ" ], [ "2001:67c:10ec::/48", "CH" ], [ "2001:67c:10f0::/48", "FR" ], [ "2001:67c:10f4::/48", "AT" ], [ "2001:67c:10f8::/48", "FR" ], [ "2001:67c:10fc::/48", "SE" ], [ "2001:67c:1100::/48", "RU" ], [ "2001:67c:1104::/48", "SE" ], [ "2001:67c:1108::/47", "FR" ], [ "2001:67c:1110::/47", "AT" ], [ "2001:67c:1118::/48", "SE" ], [ "2001:67c:111c::/48", "CH" ], [ "2001:67c:1120::/48", "PL" ], [ "2001:67c:1124::/48", "SI" ], [ "2001:67c:1128::/48", "CH" ], [ "2001:67c:112c::/48", "SE" ], [ "2001:67c:1130::/48", "SE" ], [ "2001:67c:1134::/48", "NL" ], [ "2001:67c:1138::/48", "CZ" ], [ "2001:67c:113c::/48", "UA" ], [ "2001:67c:1140::/48", "DE" ], [ "2001:67c:1144::/48", "RU" ], [ "2001:67c:1148::/48", "ES" ], [ "2001:67c:114c::/48", "RU" ], [ "2001:67c:1150::/48", "IL" ], [ "2001:67c:1154::/48", "TR" ], [ "2001:67c:1158::/48", "PL" ], [ "2001:67c:115c::/48", "RO" ], [ "2001:67c:1160::/48", "RO" ], [ "2001:67c:1164::/48", "UA" ], [ "2001:67c:1168::/48", "RU" ], [ "2001:67c:116c::/48", "SE" ], [ "2001:67c:1170::/48", "GB" ], [ "2001:67c:1174::/48", "SE" ], [ "2001:67c:1178::/48", "PL" ], [ "2001:67c:117c::/48", "UA" ], [ "2001:67c:1180::/48", "RO" ], [ "2001:67c:1184::/48", "HR" ], [ "2001:67c:1188::/48", "RU" ], [ "2001:67c:118c::/48", "FR" ], [ "2001:67c:1190::/48", "PL" ], [ "2001:67c:1194::/48", "PL" ], [ "2001:67c:1198::/47", "SA" ], [ "2001:67c:11a0::/48", "UA" ], [ "2001:67c:11a4::/48", "RO" ], [ "2001:67c:11a8::/48", "CZ" ], [ "2001:67c:11ac::/48", "SE" ], [ "2001:67c:11b0::/48", "FR" ], [ "2001:67c:11b4::/48", "ES" ], [ "2001:67c:11b8::/48", "TR" ], [ "2001:67c:11bc::/48", "GB" ], [ "2001:67c:11c0::/48", "DK" ], [ "2001:67c:11c4::/48", "RO" ], [ "2001:67c:11c8::/48", "FR" ], [ "2001:67c:11cc::/48", "SE" ], [ "2001:67c:11d0::/48", "RO" ], [ "2001:67c:11d4::/48", "UA" ], [ "2001:67c:11d8::/48", "SE" ], [ "2001:67c:11dc::/48", "DE" ], [ "2001:67c:11e0::/48", "BG" ], [ "2001:67c:11e4::/48", "PL" ], [ "2001:67c:11e8::/48", "GB" ], [ "2001:67c:11ec::/48", "TR" ], [ "2001:67c:11f4::/48", "AT" ], [ "2001:67c:11f8::/48", "DE" ], [ "2001:67c:11fc::/48", "RU" ], [ "2001:67c:1200::/46", "FR" ], [ "2001:67c:1210::/46", "RU" ], [ "2001:67c:1220::/46", "CZ" ], [ "2001:67c:1230::/46", "CH" ], [ "2001:67c:1240::/48", "IE" ], [ "2001:67c:1244::/48", "SE" ], [ "2001:67c:1248::/48", "RO" ], [ "2001:67c:124c::/48", "SE" ], [ "2001:67c:1250::/48", "LU" ], [ "2001:67c:1254::/48", "FR" ], [ "2001:67c:125c::/48", "UA" ], [ "2001:67c:1260::/48", "CZ" ], [ "2001:67c:1264::/48", "RU" ], [ "2001:67c:1268::/48", "SE" ], [ "2001:67c:126c::/48", "CH" ], [ "2001:67c:1270::/48", "GB" ], [ "2001:67c:1274::/48", "DE" ], [ "2001:67c:1278::/48", "FR" ], [ "2001:67c:1280::/48", "AT" ], [ "2001:67c:1284::/48", "AT" ], [ "2001:67c:1288::/48", "NL" ], [ "2001:67c:128c::/48", "FR" ], [ "2001:67c:1294::/48", "SE" ], [ "2001:67c:1298::/48", "NL" ], [ "2001:67c:129c::/48", "AT" ], [ "2001:67c:12a0::/48", "DE" ], [ "2001:67c:12a4::/48", "TR" ], [ "2001:67c:12a8::/48", "FI" ], [ "2001:67c:12ac::/48", "LU" ], [ "2001:67c:12b0::/48", "FR" ], [ "2001:67c:12b4::/48", "GB" ], [ "2001:67c:12b8::/48", "DE" ], [ "2001:67c:12bc::/48", "SI" ], [ "2001:67c:12c0::/47", "NO" ], [ "2001:67c:12c8::/48", "LV" ], [ "2001:67c:12cc::/48", "NL" ], [ "2001:67c:12d0::/48", "SI" ], [ "2001:67c:12d4::/48", "GB" ], [ "2001:67c:12d8::/48", "PL" ], [ "2001:67c:12dc::/48", "GB" ], [ "2001:67c:12e0::/48", "UA" ], [ "2001:67c:12e4::/48", "SA" ], [ "2001:67c:12e8::/47", "DE" ], [ "2001:67c:12f0::/48", "RU" ], [ "2001:67c:12f4::/48", "CZ" ], [ "2001:67c:12f8::/48", "DK" ], [ "2001:67c:12fc::/48", "PL" ], [ "2001:67c:1300::/48", "CH" ], [ "2001:67c:1304::/48", "RU" ], [ "2001:67c:1308::/48", "MD" ], [ "2001:67c:130c::/48", "SE" ], [ "2001:67c:1310::/48", "GB" ], [ "2001:67c:1314::/48", "CZ" ], [ "2001:67c:1318::/48", "CZ" ], [ "2001:67c:131c::/48", "RU" ], [ "2001:67c:1320::/48", "DE" ], [ "2001:67c:1324::/48", "UA" ], [ "2001:67c:1328::/48", "SI" ], [ "2001:67c:132c::/48", "SE" ], [ "2001:67c:1330::/48", "PL" ], [ "2001:67c:1334::/48", "DE" ], [ "2001:67c:1338::/48", "PL" ], [ "2001:67c:133c::/48", "AT" ], [ "2001:67c:1340::/48", "HR" ], [ "2001:67c:1344::/48", "RU" ], [ "2001:67c:1348::/48", "FR" ], [ "2001:67c:134c::/48", "CZ" ], [ "2001:67c:1350::/48", "CY" ], [ "2001:67c:1354::/48", "GB" ], [ "2001:67c:1358::/48", "RU" ], [ "2001:67c:135c::/48", "SE" ], [ "2001:67c:1360::/48", "GB" ], [ "2001:67c:1364::/48", "DE" ], [ "2001:67c:1368::/48", "CH" ], [ "2001:67c:136c::/48", "CH" ], [ "2001:67c:1370::/48", "UA" ], [ "2001:67c:1374::/48", "RU" ], [ "2001:67c:1378::/48", "UA" ], [ "2001:67c:137c::/48", "ES" ], [ "2001:67c:1380::/48", "PL" ], [ "2001:67c:1384::/48", "SE" ], [ "2001:67c:1388::/48", "GB" ], [ "2001:67c:138c::/48", "PL" ], [ "2001:67c:1390::/48", "SE" ], [ "2001:67c:1394::/48", "UA" ], [ "2001:67c:1398::/48", "SE" ], [ "2001:67c:139c::/48", "AT" ], [ "2001:67c:13a0::/48", "UA" ], [ "2001:67c:13a4::/48", "RU" ], [ "2001:67c:13a8::/48", "GB" ], [ "2001:67c:13ac::/48", "FI" ], [ "2001:67c:13b0::/48", "DE" ], [ "2001:67c:13b4::/48", "NL" ], [ "2001:67c:13b8::/48", "UA" ], [ "2001:67c:13bc::/48", "SE" ], [ "2001:67c:13c0::/48", "CH" ], [ "2001:67c:13c4::/48", "CZ" ], [ "2001:67c:13c8::/48", "LV" ], [ "2001:67c:13cc::/48", "GB" ], [ "2001:67c:13d0::/48", "RU" ], [ "2001:67c:13d4::/48", "DE" ], [ "2001:67c:13d8::/48", "SE" ], [ "2001:67c:13e0::/48", "PL" ], [ "2001:67c:13e4::/48", "RU" ], [ "2001:67c:13e8::/48", "AT" ], [ "2001:67c:13ec::/48", "PT" ], [ "2001:67c:13f0::/48", "RU" ], [ "2001:67c:13f4::/48", "SE" ], [ "2001:67c:13f8::/48", "AT" ], [ "2001:67c:13fc::/48", "CH" ], [ "2001:67c:1400::/45", "DE" ], [ "2001:67c:1420::/45", "DE" ], [ "2001:67c:1440::/45", "RU" ], [ "2001:67c:1460::/45", "DE" ], [ "2001:67c:1480::/48", "CZ" ], [ "2001:67c:1484::/48", "RU" ], [ "2001:67c:1488::/48", "SE" ], [ "2001:67c:148c::/48", "SE" ], [ "2001:67c:1490::/48", "SE" ], [ "2001:67c:1494::/48", "RU" ], [ "2001:67c:1498::/48", "DE" ], [ "2001:67c:149c::/48", "SI" ], [ "2001:67c:14a0::/48", "CZ" ], [ "2001:67c:14a4::/48", "BG" ], [ "2001:67c:14a8::/48", "SE" ], [ "2001:67c:14ac::/48", "FR" ], [ "2001:67c:14b0::/48", "NL" ], [ "2001:67c:14b4::/48", "RU" ], [ "2001:67c:14b8::/48", "DE" ], [ "2001:67c:14bc::/48", "AT" ], [ "2001:67c:14c0::/48", "NL" ], [ "2001:67c:14c4::/48", "DE" ], [ "2001:67c:14d0::/48", "NO" ], [ "2001:67c:14d4::/48", "AT" ], [ "2001:67c:14d8::/48", "SE" ], [ "2001:67c:14dc::/48", "SE" ], [ "2001:67c:14e0::/45", "DE" ], [ "2001:67c:1500::/48", "SE" ], [ "2001:67c:1504::/48", "SE" ], [ "2001:67c:1508::/48", "AT" ], [ "2001:67c:150c::/48", "CH" ], [ "2001:67c:1510::/48", "GB" ], [ "2001:67c:1514::/48", "RO" ], [ "2001:67c:1518::/48", "UA" ], [ "2001:67c:151c::/48", "AT" ], [ "2001:67c:1520::/48", "GB" ], [ "2001:67c:1524::/48", "UA" ], [ "2001:67c:1528::/48", "UA" ], [ "2001:67c:152c::/48", "GB" ], [ "2001:67c:1530::/48", "GB" ], [ "2001:67c:1534::/48", "SE" ], [ "2001:67c:1538::/48", "GB" ], [ "2001:67c:153c::/48", "SE" ], [ "2001:67c:1540::/48", "RO" ], [ "2001:67c:1544::/48", "SE" ], [ "2001:67c:154c::/48", "SE" ], [ "2001:67c:1554::/48", "TR" ], [ "2001:67c:1558::/48", "TR" ], [ "2001:67c:155c::/48", "PL" ], [ "2001:67c:1560::/46", "GB" ], [ "2001:67c:1570::/48", "RU" ], [ "2001:67c:1574::/48", "RU" ], [ "2001:67c:1578::/48", "CZ" ], [ "2001:67c:157c::/48", "RO" ], [ "2001:67c:1580::/48", "CH" ], [ "2001:67c:1584::/48", "UA" ], [ "2001:67c:1588::/48", "PL" ], [ "2001:67c:158c::/48", "DE" ], [ "2001:67c:1590::/47", "CZ" ], [ "2001:67c:1598::/48", "NL" ], [ "2001:67c:159c::/48", "PL" ], [ "2001:67c:15a0::/46", "CZ" ], [ "2001:67c:15b0::/48", "NL" ], [ "2001:67c:15b8::/48", "NL" ], [ "2001:67c:15bc::/48", "SE" ], [ "2001:67c:15c0::/48", "CH" ], [ "2001:67c:15c4::/48", "SE" ], [ "2001:67c:15c8::/48", "SE" ], [ "2001:67c:15cc::/48", "RO" ], [ "2001:67c:15d0::/48", "RU" ], [ "2001:67c:15d4::/48", "SE" ], [ "2001:67c:15d8::/48", "UA" ], [ "2001:67c:15dc::/48", "CH" ], [ "2001:67c:15e0::/48", "RO" ], [ "2001:67c:15e4::/48", "UA" ], [ "2001:67c:15e8::/48", "SE" ], [ "2001:67c:15ec::/48", "SE" ], [ "2001:67c:15f0::/48", "UA" ], [ "2001:67c:15f4::/48", "GB" ], [ "2001:67c:15f8::/48", "RU" ], [ "2001:67c:15fc::/48", "SE" ], [ "2001:67c:1600::/44", "DE" ], [ "2001:67c:1640::/44", "NO" ], [ "2001:67c:1680::/48", "GB" ], [ "2001:67c:1684::/48", "SI" ], [ "2001:67c:1688::/48", "UA" ], [ "2001:67c:168c::/48", "AT" ], [ "2001:67c:1690::/48", "FR" ], [ "2001:67c:1694::/48", "PL" ], [ "2001:67c:1698::/48", "PL" ], [ "2001:67c:169c::/48", "SE" ], [ "2001:67c:16a0::/48", "DK" ], [ "2001:67c:16a4::/48", "DK" ], [ "2001:67c:16a8::/48", "AT" ], [ "2001:67c:16ac::/48", "ES" ], [ "2001:67c:16b0::/48", "SE" ], [ "2001:67c:16b4::/48", "NL" ], [ "2001:67c:16b8::/48", "BG" ], [ "2001:67c:16bc::/48", "SE" ], [ "2001:67c:16c0::/48", "CZ" ], [ "2001:67c:16c4::/48", "SI" ], [ "2001:67c:16c8::/48", "CZ" ], [ "2001:67c:16cc::/48", "RU" ], [ "2001:67c:16d0::/47", "GB" ], [ "2001:67c:16d8::/48", "RO" ], [ "2001:67c:16dc::/48", "CH" ], [ "2001:67c:16e0::/48", "RO" ], [ "2001:67c:16e4::/48", "HR" ], [ "2001:67c:16e8::/48", "PL" ], [ "2001:67c:16ec::/48", "RO" ], [ "2001:67c:16f0::/48", "DE" ], [ "2001:67c:16f4::/48", "SI" ], [ "2001:67c:16f8::/48", "PL" ], [ "2001:67c:16fc::/48", "SE" ], [ "2001:67c:1700::/48", "DE" ], [ "2001:67c:1704::/48", "PL" ], [ "2001:67c:1708::/48", "RO" ], [ "2001:67c:170c::/48", "CZ" ], [ "2001:67c:1710::/48", "GB" ], [ "2001:67c:1720::/48", "UA" ], [ "2001:67c:1724::/48", "NL" ], [ "2001:67c:1728::/48", "UA" ], [ "2001:67c:172c::/48", "GB" ], [ "2001:67c:1730::/48", "GB" ], [ "2001:67c:1734::/48", "NL" ], [ "2001:67c:1738::/48", "IL" ], [ "2001:67c:173c::/48", "DE" ], [ "2001:67c:1740::/48", "FR" ], [ "2001:67c:1744::/48", "DK" ], [ "2001:67c:1748::/48", "DE" ], [ "2001:67c:174c::/48", "SE" ], [ "2001:67c:1750::/48", "AT" ], [ "2001:67c:1754::/48", "SE" ], [ "2001:67c:1758::/48", "DE" ], [ "2001:67c:175c::/48", "DE" ], [ "2001:67c:1760::/48", "DK" ], [ "2001:67c:1764::/48", "RO" ], [ "2001:67c:1768::/48", "RU" ], [ "2001:67c:176c::/48", "UA" ], [ "2001:67c:1770::/48", "SE" ], [ "2001:67c:1774::/48", "RU" ], [ "2001:67c:177c::/48", "LT" ], [ "2001:67c:1780::/48", "CH" ], [ "2001:67c:1784::/48", "SE" ], [ "2001:67c:1788::/48", "RO" ], [ "2001:67c:178c::/48", "RO" ], [ "2001:67c:1790::/48", "RU" ], [ "2001:67c:1794::/48", "SE" ], [ "2001:67c:1798::/48", "CZ" ], [ "2001:67c:179c::/48", "SE" ], [ "2001:67c:17a0::/48", "FI" ], [ "2001:67c:17a8::/48", "SE" ], [ "2001:67c:17ac::/48", "SE" ], [ "2001:67c:17b0::/48", "PL" ], [ "2001:67c:17b4::/48", "CZ" ], [ "2001:67c:17b8::/48", "CZ" ], [ "2001:67c:17bc::/48", "SE" ], [ "2001:67c:17c0::/48", "SE" ], [ "2001:67c:17c4::/48", "SE" ], [ "2001:67c:17c8::/48", "DE" ], [ "2001:67c:17cc::/48", "SE" ], [ "2001:67c:17d0::/48", "CZ" ], [ "2001:67c:17d4::/48", "DE" ], [ "2001:67c:17d8::/48", "PL" ], [ "2001:67c:17dc::/48", "SE" ], [ "2001:67c:17e0::/48", "SE" ], [ "2001:67c:17e4::/48", "NO" ], [ "2001:67c:17e8::/48", "NO" ], [ "2001:67c:17ec::/48", "NL" ], [ "2001:67c:17f0::/48", "SE" ], [ "2001:67c:17f4::/48", "SE" ], [ "2001:67c:17f8::/48", "RU" ], [ "2001:67c:17fc::/48", "RO" ], [ "2001:67c:1800::/48", "SE" ], [ "2001:67c:1804::/48", "RO" ], [ "2001:67c:1808::/47", "BE" ], [ "2001:67c:1810::/48", "BE" ], [ "2001:67c:1814::/48", "FR" ], [ "2001:67c:1818::/48", "RO" ], [ "2001:67c:181c::/48", "DE" ], [ "2001:67c:1820::/48", "DE" ], [ "2001:67c:1828::/48", "CZ" ], [ "2001:67c:182c::/48", "RO" ], [ "2001:67c:1830::/48", "SE" ], [ "2001:67c:1834::/48", "BE" ], [ "2001:67c:1838::/48", "BE" ], [ "2001:67c:183c::/48", "BE" ], [ "2001:67c:1840::/48", "RU" ], [ "2001:67c:1844::/48", "RO" ], [ "2001:67c:1848::/48", "UA" ], [ "2001:67c:184c::/48", "FR" ], [ "2001:67c:1850::/48", "RU" ], [ "2001:67c:1854::/48", "RO" ], [ "2001:67c:1858::/48", "DK" ], [ "2001:67c:185c::/48", "DK" ], [ "2001:67c:1860::/48", "RU" ], [ "2001:67c:1864::/48", "AT" ], [ "2001:67c:1868::/48", "RU" ], [ "2001:67c:186c::/48", "SE" ], [ "2001:67c:1870::/48", "NL" ], [ "2001:67c:1874::/48", "CZ" ], [ "2001:67c:1878::/48", "RO" ], [ "2001:67c:187c::/48", "RO" ], [ "2001:67c:1880::/48", "SE" ], [ "2001:67c:1884::/48", "GB" ], [ "2001:67c:1888::/48", "SE" ], [ "2001:67c:188c::/48", "PL" ], [ "2001:67c:1890::/48", "SE" ], [ "2001:67c:1894::/48", "SE" ], [ "2001:67c:1898::/48", "SE" ], [ "2001:67c:189c::/48", "SE" ], [ "2001:67c:18a0::/48", "NL" ], [ "2001:67c:18a4::/48", "RU" ], [ "2001:67c:18a8::/48", "BY" ], [ "2001:67c:18ac::/48", "RU" ], [ "2001:67c:18b0::/48", "DE" ], [ "2001:67c:18b4::/48", "DK" ], [ "2001:67c:18b8::/48", "DE" ], [ "2001:67c:18bc::/48", "DE" ], [ "2001:67c:18c0::/48", "RO" ], [ "2001:67c:18c4::/48", "RO" ], [ "2001:67c:18c8::/47", "SA" ], [ "2001:67c:18d0::/48", "RU" ], [ "2001:67c:18d4::/48", "NZ" ], [ "2001:67c:18d8::/48", "SE" ], [ "2001:67c:18dc::/48", "LI" ], [ "2001:67c:18e0::/48", "SI" ], [ "2001:67c:18e4::/48", "GB" ], [ "2001:67c:18e8::/48", "DE" ], [ "2001:67c:18ec::/48", "DE" ], [ "2001:67c:18f0::/48", "DE" ], [ "2001:67c:18f4::/48", "SE" ], [ "2001:67c:18f8::/48", "RO" ], [ "2001:67c:18fc::/48", "SE" ], [ "2001:67c:1900::/46", "BE" ], [ "2001:67c:1910::/48", "SE" ], [ "2001:67c:1914::/48", "RU" ], [ "2001:67c:1918::/48", "NL" ], [ "2001:67c:191c::/48", "SE" ], [ "2001:67c:1920::/48", "SE" ], [ "2001:67c:1924::/48", "DE" ], [ "2001:67c:1928::/48", "DE" ], [ "2001:67c:192c::/48", "RO" ], [ "2001:67c:1930::/46", "AT" ], [ "2001:67c:1940::/48", "GB" ], [ "2001:67c:1944::/48", "DE" ], [ "2001:67c:1948::/48", "UA" ], [ "2001:67c:194c::/48", "DE" ], [ "2001:67c:1950::/48", "DE" ], [ "2001:67c:1954::/48", "GB" ], [ "2001:67c:1958::/48", "DK" ], [ "2001:67c:195c::/48", "ES" ], [ "2001:67c:1960::/48", "RO" ], [ "2001:67c:1964::/48", "UA" ], [ "2001:67c:1968::/48", "DE" ], [ "2001:67c:196c::/48", "RO" ], [ "2001:67c:1970::/48", "RU" ], [ "2001:67c:1974::/48", "AT" ], [ "2001:67c:1978::/48", "RO" ], [ "2001:67c:197c::/48", "NO" ], [ "2001:67c:1980::/48", "FR" ], [ "2001:67c:1984::/48", "BG" ], [ "2001:67c:1a00::/42", "NL" ], [ "2001:67c:1b00::/48", "RU" ], [ "2001:67c:1b04::/48", "RU" ], [ "::1.0.0.0/120", "AU" ], [ "::1.0.1.0/120", "CN" ], [ "::1.0.2.0/119", "CN" ], [ "::1.0.4.0/120", "AU" ], [ "::1.0.5.0/123", "AU" ], [ "::1.0.5.32/123", "AU" ], [ "::1.0.5.64/122", "AU" ], [ "::1.0.5.128/121", "AU" ], [ "::1.0.6.0/119", "AU" ], [ "::1.0.8.0/117", "CN" ], [ "::1.0.16.0/116", "JP" ], [ "::1.0.32.0/115", "CN" ], [ "::1.0.64.0/114", "JP" ], [ "::1.0.128.0/120", "TH" ], [ "::1.0.129.0/120", "TH" ], [ "::1.0.130.0/119", "TH" ], [ "::1.0.132.0/120", "TH" ], [ "::1.0.133.0/120", "TH" ], [ "::1.0.134.0/119", "TH" ], [ "::1.0.136.0/117", "TH" ], [ "::1.0.144.0/120", "TH" ], [ "::1.0.145.0/120", "TH" ], [ "::1.0.146.0/119", "TH" ], [ "::1.0.148.0/120", "TH" ], [ "::1.0.149.0/120", "TH" ], [ "::1.0.150.0/119", "TH" ], [ "::1.0.152.0/118", "TH" ], [ "::1.0.156.0/119", "TH" ], [ "::1.0.158.0/120", "TH" ], [ "::1.0.159.0/120", "TH" ], [ "::1.0.160.0/118", "TH" ], [ "::1.0.164.0/119", "TH" ], [ "::1.0.166.0/120", "TH" ], [ "::1.0.167.0/120", "TH" ], [ "::1.0.168.0/118", "TH" ], [ "::1.0.172.0/119", "TH" ], [ "::1.0.174.0/120", "TH" ], [ "::1.0.175.0/120", "TH" ], [ "::1.0.176.0/118", "TH" ], [ "::1.0.180.0/119", "TH" ], [ "::1.0.182.0/120", "TH" ], [ "::1.0.183.0/120", "TH" ], [ "::1.0.184.0/120", "TH" ], [ "::1.0.185.0/120", "TH" ], [ "::1.0.186.0/120", "TH" ], [ "::1.0.187.0/120", "TH" ], [ "::1.0.188.0/120", "TH" ], [ "::1.0.189.0/120", "TH" ], [ "::1.0.190.0/120", "TH" ], [ "::1.0.191.0/120", "TH" ], [ "::1.0.192.0/117", "TH" ], [ "::1.0.200.0/120", "TH" ], [ "::1.0.201.0/120", "TH" ], [ "::1.0.202.0/119", "TH" ], [ "::1.0.204.0/118", "TH" ], [ "::1.0.208.0/118", "TH" ], [ "::1.0.212.0/119", "TH" ], [ "::1.0.214.0/120", "TH" ], [ "::1.0.215.0/120", "TH" ], [ "::1.0.216.0/119", "TH" ], [ "::1.0.218.0/119", "TH" ], [ "::1.0.220.0/121", "TH" ], [ "::1.0.220.128/121", "TH" ], [ "::1.0.221.0/120", "TH" ], [ "::1.0.222.0/119", "TH" ], [ "::1.0.224.0/120", "TH" ], [ "::1.0.225.0/120", "TH" ], [ "::1.0.226.0/120", "TH" ], [ "::1.0.227.0/120", "TH" ], [ "::1.0.228.0/120", "TH" ], [ "::1.0.229.0/120", "TH" ], [ "::1.0.230.0/120", "TH" ], [ "::1.0.231.0/120", "TH" ], [ "::1.0.232.0/120", "TH" ], [ "::1.0.233.0/120", "TH" ], [ "::1.0.234.0/120", "TH" ], [ "::1.0.235.0/120", "TH" ], [ "::1.0.236.0/119", "TH" ], [ "::1.0.238.0/119", "TH" ], [ "::1.0.240.0/120", "TH" ], [ "::1.0.241.0/120", "TH" ], [ "::1.0.242.0/120", "TH" ], [ "::1.0.243.0/120", "TH" ], [ "::1.0.244.0/120", "TH" ], [ "::1.0.245.0/120", "TH" ], [ "::1.0.246.0/120", "TH" ], [ "::1.0.247.0/120", "TH" ], [ "::1.0.248.0/119", "TH" ], [ "::1.0.250.0/120", "TH" ], [ "::1.0.251.0/120", "TH" ], [ "::1.0.252.0/119", "TH" ], [ "::1.0.254.0/120", "TH" ], [ "::1.0.255.0/120", "TH" ], [ "::1.1.0.0/120", "CN" ], [ "::1.1.1.0/120", "AU" ], [ "::1.1.2.0/119", "CN" ], [ "::1.1.4.0/118", "CN" ], [ "::1.1.8.0/117", "CN" ], [ "::1.1.16.0/116", "CN" ], [ "::1.1.32.0/115", "CN" ], [ "::1.1.64.0/114", "JP" ], [ "::1.1.128.0/120", "TH" ], [ "::1.1.129.0/120", "TH" ], [ "::1.1.130.0/119", "TH" ], [ "::1.1.132.0/118", "TH" ], [ "::1.1.136.0/120", "TH" ], [ "::1.1.137.0/120", "TH" ], [ "::1.1.138.0/119", "TH" ], [ "::1.1.140.0/118", "TH" ], [ "::1.1.144.0/119", "TH" ], [ "::1.1.146.0/120", "TH" ], [ "::1.1.147.0/120", "TH" ], [ "::1.1.148.0/120", "TH" ], [ "::1.1.149.0/120", "TH" ], [ "::1.1.150.0/119", "TH" ], [ "::1.1.152.0/119", "TH" ], [ "::1.1.154.0/120", "TH" ], [ "::1.1.155.0/120", "TH" ], [ "::1.1.156.0/119", "TH" ], [ "::1.1.158.0/120", "TH" ], [ "::1.1.159.0/120", "TH" ], [ "::1.1.160.0/120", "TH" ], [ "::1.1.161.0/120", "TH" ], [ "::1.1.162.0/119", "TH" ], [ "::1.1.164.0/119", "TH" ], [ "::1.1.166.0/120", "TH" ], [ "::1.1.167.0/120", "TH" ], [ "::1.1.168.0/118", "TH" ], [ "::1.1.172.0/119", "TH" ], [ "::1.1.174.0/120", "TH" ], [ "::1.1.175.0/120", "TH" ], [ "::1.1.176.0/117", "TH" ], [ "::1.1.184.0/120", "TH" ], [ "::1.1.185.0/120", "TH" ], [ "::1.1.186.0/119", "TH" ], [ "::1.1.188.0/118", "TH" ], [ "::1.1.192.0/119", "TH" ], [ "::1.1.194.0/120", "TH" ], [ "::1.1.195.0/120", "TH" ], [ "::1.1.196.0/120", "TH" ], [ "::1.1.197.0/120", "TH" ], [ "::1.1.198.0/119", "TH" ], [ "::1.1.200.0/118", "TH" ], [ "::1.1.204.0/120", "TH" ], [ "::1.1.205.0/120", "TH" ], [ "::1.1.206.0/120", "TH" ], [ "::1.1.207.0/120", "TH" ], [ "::1.1.208.0/118", "TH" ], [ "::1.1.212.0/119", "TH" ], [ "::1.1.214.0/120", "TH" ], [ "::1.1.215.0/120", "TH" ], [ "::1.1.216.0/117", "TH" ], [ "::1.1.224.0/120", "TH" ], [ "::1.1.225.0/120", "TH" ], [ "::1.1.226.0/120", "TH" ], [ "::1.1.227.0/120", "TH" ], [ "::1.1.228.0/120", "TH" ], [ "::1.1.229.0/120", "TH" ], [ "::1.1.230.0/120", "TH" ], [ "::1.1.231.0/120", "TH" ], [ "::1.1.232.0/117", "TH" ], [ "::1.1.240.0/119", "TH" ], [ "::1.1.242.0/120", "TH" ], [ "::1.1.243.0/120", "TH" ], [ "::1.1.244.0/118", "TH" ], [ "::1.1.248.0/120", "TH" ], [ "::1.1.249.0/120", "TH" ], [ "::1.1.250.0/119", "TH" ], [ "::1.1.252.0/118", "TH" ], [ "::1.2.0.0/119", "CN" ], [ "::1.2.2.0/120", "CN" ], [ "::1.2.3.0/120", "AU" ], [ "::1.2.4.0/118", "CN" ], [ "::1.2.8.0/117", "CN" ], [ "::1.2.16.0/116", "CN" ], [ "::1.2.32.0/115", "CN" ], [ "::1.2.64.0/114", "CN" ], [ "::1.2.128.0/119", "TH" ], [ "::1.2.130.0/119", "TH" ], [ "::1.2.132.0/118", "TH" ], [ "::1.2.136.0/118", "TH" ], [ "::1.2.140.0/120", "TH" ], [ "::1.2.141.0/120", "TH" ], [ "::1.2.142.0/119", "TH" ], [ "::1.2.144.0/119", "TH" ], [ "::1.2.146.0/119", "TH" ], [ "::1.2.148.0/120", "TH" ], [ "::1.2.149.0/120", "TH" ], [ "::1.2.150.0/119", "TH" ], [ "::1.2.152.0/118", "TH" ], [ "::1.2.156.0/119", "TH" ], [ "::1.2.158.0/120", "TH" ], [ "::1.2.159.0/120", "TH" ], [ "::1.2.160.0/119", "TH" ], [ "::1.2.162.0/120", "TH" ], [ "::1.2.163.0/120", "TH" ], [ "::1.2.164.0/118", "TH" ], [ "::1.2.168.0/120", "TH" ], [ "::1.2.169.0/120", "TH" ], [ "::1.2.170.0/119", "TH" ], [ "::1.2.172.0/119", "TH" ], [ "::1.2.174.0/120", "TH" ], [ "::1.2.175.0/120", "TH" ], [ "::1.2.176.0/116", "TH" ], [ "::1.2.192.0/119", "TH" ], [ "::1.2.194.0/120", "TH" ], [ "::1.2.195.0/120", "TH" ], [ "::1.2.196.0/118", "TH" ], [ "::1.2.200.0/119", "TH" ], [ "::1.2.202.0/120", "TH" ], [ "::1.2.203.0/120", "TH" ], [ "::1.2.204.0/120", "TH" ], [ "::1.2.205.0/120", "TH" ], [ "::1.2.206.0/120", "TH" ], [ "::1.2.207.0/120", "TH" ], [ "::1.2.208.0/120", "TH" ], [ "::1.2.209.0/120", "TH" ], [ "::1.2.210.0/119", "TH" ], [ "::1.2.212.0/120", "TH" ], [ "::1.2.213.0/120", "TH" ], [ "::1.2.214.0/120", "TH" ], [ "::1.2.215.0/120", "TH" ], [ "::1.2.216.0/119", "TH" ], [ "::1.2.218.0/120", "TH" ], [ "::1.2.219.0/120", "TH" ], [ "::1.2.220.0/119", "TH" ], [ "::1.2.222.0/120", "TH" ], [ "::1.2.223.0/120", "TH" ], [ "::1.2.224.0/120", "TH" ], [ "::1.2.225.0/120", "TH" ], [ "::1.2.226.0/120", "TH" ], [ "::1.2.227.0/120", "TH" ], [ "::1.2.228.0/118", "TH" ], [ "::1.2.232.0/117", "TH" ], [ "::1.2.240.0/118", "TH" ], [ "::1.2.244.0/119", "TH" ], [ "::1.2.246.0/120", "TH" ], [ "::1.2.247.0/120", "TH" ], [ "::1.2.248.0/118", "TH" ], [ "::1.2.252.0/119", "TH" ], [ "::1.2.254.0/119", "TH" ], [ "::1.3.0.0/112", "CN" ], [ "::1.4.0.0/120", "AU" ], [ "::1.4.1.0/120", "CN" ], [ "::1.4.2.0/119", "CN" ], [ "::1.4.4.0/118", "CN" ], [ "::1.4.8.0/117", "CN" ], [ "::1.4.16.0/116", "CN" ], [ "::1.4.32.0/115", "CN" ], [ "::1.4.64.0/114", "CN" ], [ "::1.4.128.0/120", "TH" ], [ "::1.4.129.0/120", "TH" ], [ "::1.4.130.0/120", "TH" ], [ "::1.4.131.0/120", "TH" ], [ "::1.4.132.0/119", "TH" ], [ "::1.4.134.0/120", "TH" ], [ "::1.4.135.0/120", "TH" ], [ "::1.4.136.0/120", "TH" ], [ "::1.4.137.0/120", "TH" ], [ "::1.4.138.0/119", "TH" ], [ "::1.4.140.0/120", "TH" ], [ "::1.4.141.0/120", "TH" ], [ "::1.4.142.0/119", "TH" ], [ "::1.4.144.0/119", "TH" ], [ "::1.4.146.0/120", "TH" ], [ "::1.4.147.0/120", "TH" ], [ "::1.4.148.0/119", "TH" ], [ "::1.4.150.0/119", "TH" ], [ "::1.4.152.0/120", "TH" ], [ "::1.4.153.0/120", "TH" ], [ "::1.4.154.0/119", "TH" ], [ "::1.4.156.0/118", "TH" ], [ "::1.4.160.0/118", "TH" ], [ "::1.4.164.0/119", "TH" ], [ "::1.4.166.0/120", "TH" ], [ "::1.4.167.0/120", "TH" ], [ "::1.4.168.0/119", "TH" ], [ "::1.4.170.0/120", "TH" ], [ "::1.4.171.0/120", "TH" ], [ "::1.4.172.0/120", "TH" ], [ "::1.4.173.0/120", "TH" ], [ "::1.4.174.0/120", "TH" ], [ "::1.4.175.0/120", "TH" ], [ "::1.4.176.0/120", "TH" ], [ "::1.4.177.0/120", "TH" ], [ "::1.4.178.0/120", "TH" ], [ "::1.4.179.0/120", "TH" ], [ "::1.4.180.0/120", "TH" ], [ "::1.4.181.0/120", "TH" ], [ "::1.4.182.0/119", "TH" ], [ "::1.4.184.0/120", "TH" ], [ "::1.4.185.0/120", "TH" ], [ "::1.4.186.0/119", "TH" ], [ "::1.4.188.0/119", "TH" ], [ "::1.4.190.0/119", "TH" ], [ "::1.4.192.0/119", "TH" ], [ "::1.4.194.0/120", "TH" ], [ "::1.4.195.0/120", "TH" ], [ "::1.4.196.0/120", "TH" ], [ "::1.4.197.0/120", "TH" ], [ "::1.4.198.0/119", "TH" ], [ "::1.4.200.0/120", "TH" ], [ "::1.4.201.0/120", "TH" ], [ "::1.4.202.0/119", "TH" ], [ "::1.4.204.0/119", "TH" ], [ "::1.4.206.0/119", "TH" ], [ "::1.4.208.0/117", "TH" ], [ "::1.4.216.0/119", "TH" ], [ "::1.4.218.0/119", "TH" ], [ "::1.4.220.0/118", "TH" ], [ "::1.4.224.0/119", "TH" ], [ "::1.4.226.0/119", "TH" ], [ "::1.4.228.0/120", "TH" ], [ "::1.4.229.0/120", "TH" ], [ "::1.4.230.0/120", "TH" ], [ "::1.4.231.0/120", "TH" ], [ "::1.4.232.0/120", "TH" ], [ "::1.4.233.0/120", "TH" ], [ "::1.4.234.0/119", "TH" ], [ "::1.4.236.0/119", "TH" ], [ "::1.4.238.0/120", "TH" ], [ "::1.4.239.0/120", "TH" ], [ "::1.4.240.0/119", "TH" ], [ "::1.4.242.0/120", "TH" ], [ "::1.4.243.0/120", "TH" ], [ "::1.4.244.0/118", "TH" ], [ "::1.4.248.0/120", "TH" ], [ "::1.4.249.0/120", "TH" ], [ "::1.4.250.0/119", "TH" ], [ "::1.4.252.0/118", "TH" ], [ "::1.5.0.0/112", "JP" ], [ "::1.6.0.0/111", "IN" ], [ "::1.8.0.0/112", "CN" ], [ "::1.9.0.0/120", "MY" ], [ "::1.9.1.0/120", "MY" ], [ "::1.9.2.0/119", "MY" ], [ "::1.9.4.0/118", "MY" ], [ "::1.9.8.0/119", "MY" ], [ "::1.9.10.0/120", "MY" ], [ "::1.9.11.0/120", "MY" ], [ "::1.9.12.0/118", "MY" ], [ "::1.9.16.0/119", "MY" ], [ "::1.9.18.0/119", "MY" ], [ "::1.9.20.0/120", "MY" ], [ "::1.9.21.0/120", "MY" ], [ "::1.9.22.0/119", "MY" ], [ "::1.9.24.0/119", "MY" ], [ "::1.9.26.0/119", "MY" ], [ "::1.9.28.0/118", "MY" ], [ "::1.9.32.0/120", "MY" ], [ "::1.9.33.0/120", "MY" ], [ "::1.9.34.0/119", "MY" ], [ "::1.9.36.0/118", "MY" ], [ "::1.9.40.0/118", "MY" ], [ "::1.9.44.0/119", "MY" ], [ "::1.9.46.0/120", "MY" ], [ "::1.9.47.0/120", "MY" ], [ "::1.9.48.0/120", "MY" ], [ "::1.9.49.0/120", "MY" ], [ "::1.9.50.0/119", "MY" ], [ "::1.9.52.0/119", "MY" ], [ "::1.9.54.0/120", "MY" ], [ "::1.9.55.0/120", "MY" ], [ "::1.9.56.0/119", "MY" ], [ "::1.9.58.0/120", "MY" ], [ "::1.9.59.0/120", "MY" ], [ "::1.9.60.0/118", "MY" ], [ "::1.9.64.0/120", "MY" ], [ "::1.9.65.0/120", "MY" ], [ "::1.9.66.0/119", "MY" ], [ "::1.9.68.0/118", "MY" ], [ "::1.9.72.0/119", "MY" ], [ "::1.9.74.0/120", "MY" ], [ "::1.9.75.0/120", "MY" ], [ "::1.9.76.0/118", "MY" ], [ "::1.9.80.0/116", "MY" ], [ "::1.9.96.0/120", "MY" ], [ "::1.9.97.0/120", "MY" ], [ "::1.9.98.0/119", "MY" ], [ "::1.9.100.0/120", "MY" ], [ "::1.9.101.0/120", "MY" ], [ "::1.9.102.0/120", "MY" ], [ "::1.9.103.0/120", "MY" ], [ "::1.9.104.0/120", "MY" ], [ "::1.9.105.0/120", "MY" ], [ "::1.9.106.0/120", "MY" ], [ "::1.9.107.0/120", "MY" ], [ "::1.9.108.0/118", "MY" ], [ "::1.9.112.0/116", "MY" ], [ "::1.9.128.0/118", "MY" ], [ "::1.9.132.0/119", "MY" ], [ "::1.9.134.0/120", "MY" ], [ "::1.9.135.0/120", "MY" ], [ "::1.9.136.0/119", "MY" ], [ "::1.9.138.0/120", "MY" ], [ "::1.9.139.0/120", "MY" ], [ "::1.9.140.0/118", "MY" ], [ "::1.9.144.0/118", "MY" ], [ "::1.9.148.0/119", "MY" ], [ "::1.9.150.0/120", "MY" ], [ "::1.9.151.0/120", "MY" ], [ "::1.9.152.0/119", "MY" ], [ "::1.9.154.0/120", "MY" ], [ "::1.9.155.0/120", "MY" ], [ "::1.9.156.0/120", "MY" ], [ "::1.9.157.0/120", "MY" ], [ "::1.9.158.0/120", "MY" ], [ "::1.9.159.0/120", "MY" ], [ "::1.9.160.0/119", "MY" ], [ "::1.9.162.0/120", "MY" ], [ "::1.9.163.0/120", "MY" ], [ "::1.9.164.0/118", "MY" ], [ "::1.9.168.0/118", "MY" ], [ "::1.9.172.0/119", "MY" ], [ "::1.9.174.0/120", "MY" ], [ "::1.9.175.0/120", "MY" ], [ "::1.9.176.0/120", "MY" ], [ "::1.9.177.0/120", "MY" ], [ "::1.9.178.0/120", "MY" ], [ "::1.9.179.0/120", "MY" ], [ "::1.9.180.0/120", "MY" ], [ "::1.9.181.0/120", "MY" ], [ "::1.9.182.0/119", "MY" ], [ "::1.9.184.0/120", "MY" ], [ "::1.9.185.0/120", "MY" ], [ "::1.9.186.0/120", "MY" ], [ "::1.9.187.0/120", "MY" ], [ "::1.9.188.0/120", "MY" ], [ "::1.9.189.0/120", "MY" ], [ "::1.9.190.0/119", "MY" ], [ "::1.9.192.0/119", "MY" ], [ "::1.9.194.0/120", "MY" ], [ "::1.9.195.0/120", "MY" ], [ "::1.9.196.0/118", "MY" ], [ "::1.9.200.0/119", "MY" ], [ "::1.9.202.0/120", "MY" ], [ "::1.9.203.0/120", "MY" ], [ "::1.9.204.0/120", "MY" ], [ "::1.9.205.0/120", "MY" ], [ "::1.9.206.0/119", "MY" ], [ "::1.9.208.0/120", "MY" ], [ "::1.9.209.0/120", "MY" ], [ "::1.9.210.0/119", "MY" ], [ "::1.9.212.0/118", "MY" ], [ "::1.9.216.0/117", "MY" ], [ "::1.9.224.0/116", "MY" ], [ "::1.9.240.0/118", "MY" ], [ "::1.9.244.0/120", "MY" ], [ "::1.9.245.0/120", "MY" ], [ "::1.9.246.0/119", "MY" ], [ "::1.9.248.0/117", "MY" ], [ "::1.10.0.0/117", "CN" ], [ "::1.10.8.0/119", "CN" ], [ "::1.10.10.0/120", "AU" ], [ "::1.10.11.0/120", "CN" ], [ "::1.10.12.0/118", "CN" ], [ "::1.10.16.0/116", "CN" ], [ "::1.10.32.0/115", "CN" ], [ "::1.10.64.0/114", "CN" ], [ "::1.10.128.0/114", "TH" ], [ "::1.10.192.0/116", "TH" ], [ "::1.10.208.0/118", "TH" ], [ "::1.10.212.0/120", "TH" ], [ "::1.10.213.0/120", "TH" ], [ "::1.10.214.0/119", "TH" ], [ "::1.10.216.0/117", "TH" ], [ "::1.10.224.0/117", "TH" ], [ "::1.10.232.0/120", "TH" ], [ "::1.10.233.0/120", "TH" ], [ "::1.10.234.0/119", "TH" ], [ "::1.10.236.0/118", "TH" ], [ "::1.10.240.0/116", "TH" ], [ "::1.11.0.0/112", "KR" ], [ "::1.12.0.0/110", "CN" ], [ "::1.16.0.0/110", "KR" ], [ "::1.20.0.0/119", "TH" ], [ "::1.20.2.0/119", "TH" ], [ "::1.20.4.0/118", "TH" ], [ "::1.20.8.0/117", "TH" ], [ "::1.20.16.0/116", "TH" ], [ "::1.20.32.0/115", "TH" ], [ "::1.20.64.0/114", "TH" ], [ "::1.20.128.0/120", "TH" ], [ "::1.20.129.0/120", "TH" ], [ "::1.20.130.0/119", "TH" ], [ "::1.20.132.0/119", "TH" ], [ "::1.20.134.0/120", "TH" ], [ "::1.20.135.0/120", "TH" ], [ "::1.20.136.0/117", "TH" ], [ "::1.20.144.0/116", "TH" ], [ "::1.20.160.0/115", "TH" ], [ "::1.20.192.0/114", "TH" ], [ "::1.21.0.0/116", "JP" ], [ "::1.21.16.0/119", "JP" ], [ "::1.21.18.0/120", "JP" ], [ "::1.21.19.0/120", "JP" ], [ "::1.21.20.0/119", "JP" ], [ "::1.21.22.0/120", "JP" ], [ "::1.21.23.0/120", "JP" ], [ "::1.21.24.0/120", "JP" ], [ "::1.21.25.0/120", "JP" ], [ "::1.21.26.0/119", "JP" ], [ "::1.21.28.0/118", "JP" ], [ "::1.21.32.0/115", "JP" ], [ "::1.21.64.0/115", "JP" ], [ "::1.21.96.0/118", "JP" ], [ "::1.21.100.0/119", "JP" ], [ "::1.21.102.0/120", "JP" ], [ "::1.21.103.0/120", "JP" ], [ "::1.21.104.0/117", "JP" ], [ "::1.21.112.0/116", "JP" ], [ "::1.21.128.0/113", "JP" ], [ "::1.22.0.0/116", "IN" ], [ "::1.22.16.0/119", "IN" ], [ "::1.22.18.0/119", "IN" ], [ "::1.22.20.0/118", "IN" ], [ "::1.22.24.0/120", "IN" ], [ "::1.22.25.0/120", "IN" ], [ "::1.22.26.0/119", "IN" ], [ "::1.22.28.0/118", "IN" ], [ "::1.22.32.0/119", "IN" ], [ "::1.22.34.0/120", "IN" ], [ "::1.22.35.0/120", "IN" ], [ "::1.22.36.0/119", "IN" ], [ "::1.22.38.0/119", "IN" ], [ "::1.22.40.0/120", "IN" ], [ "::1.22.41.0/120", "IN" ], [ "::1.22.42.0/119", "IN" ], [ "::1.22.44.0/120", "IN" ], [ "::1.22.45.0/120", "IN" ], [ "::1.22.46.0/119", "IN" ], [ "::1.22.48.0/119", "IN" ], [ "::1.22.50.0/120", "IN" ], [ "::1.22.51.0/120", "IN" ], [ "::1.22.52.0/118", "IN" ], [ "::1.22.56.0/118", "IN" ], [ "::1.22.60.0/120", "IN" ], [ "::1.22.61.0/120", "IN" ], [ "::1.22.62.0/119", "IN" ], [ "::1.22.64.0/119", "IN" ], [ "::1.22.66.0/120", "IN" ], [ "::1.22.67.0/120", "IN" ], [ "::1.22.68.0/119", "IN" ], [ "::1.22.70.0/119", "IN" ], [ "::1.22.72.0/119", "IN" ], [ "::1.22.74.0/119", "IN" ], [ "::1.22.76.0/120", "IN" ], [ "::1.22.77.0/120", "IN" ], [ "::1.22.78.0/120", "IN" ], [ "::1.22.79.0/120", "IN" ], [ "::1.22.80.0/118", "IN" ], [ "::1.22.84.0/118", "IN" ], [ "::1.22.88.0/120", "IN" ], [ "::1.22.89.0/120", "IN" ], [ "::1.22.90.0/119", "IN" ], [ "::1.22.92.0/118", "IN" ], [ "::1.22.96.0/119", "IN" ], [ "::1.22.98.0/119", "IN" ], [ "::1.22.100.0/120", "IN" ], [ "::1.22.101.0/120", "IN" ], [ "::1.22.102.0/119", "IN" ], [ "::1.22.104.0/120", "IN" ], [ "::1.22.105.0/120", "IN" ], [ "::1.22.106.0/120", "IN" ], [ "::1.22.107.0/120", "IN" ], [ "::1.22.108.0/118", "IN" ], [ "::1.22.112.0/120", "IN" ], [ "::1.22.113.0/120", "IN" ], [ "::1.22.114.0/119", "IN" ], [ "::1.22.116.0/120", "IN" ], [ "::1.22.117.0/120", "IN" ], [ "::1.22.118.0/120", "IN" ], [ "::1.22.119.0/120", "IN" ], [ "::1.22.120.0/119", "IN" ], [ "::1.22.122.0/119", "IN" ], [ "::1.22.124.0/121", "IN" ], [ "::1.22.124.128/121", "IN" ], [ "::1.22.125.0/120", "IN" ], [ "::1.22.126.0/119", "IN" ], [ "::1.22.128.0/120", "IN" ], [ "::1.22.129.0/120", "IN" ], [ "::1.22.130.0/119", "IN" ], [ "::1.22.132.0/119", "IN" ], [ "::1.22.134.0/119", "IN" ], [ "::1.22.136.0/120", "IN" ], [ "::1.22.137.0/120", "IN" ], [ "::1.22.138.0/119", "IN" ], [ "::1.22.140.0/120", "IN" ], [ "::1.22.141.0/120", "IN" ], [ "::1.22.142.0/120", "IN" ], [ "::1.22.143.0/120", "IN" ], [ "::1.22.144.0/119", "IN" ], [ "::1.22.146.0/120", "IN" ], [ "::1.22.147.0/120", "IN" ], [ "::1.22.148.0/120", "IN" ], [ "::1.22.149.0/120", "IN" ], [ "::1.22.150.0/119", "IN" ], [ "::1.22.152.0/119", "IN" ], [ "::1.22.154.0/120", "IN" ], [ "::1.22.155.0/120", "IN" ], [ "::1.22.156.0/120", "IN" ], [ "::1.22.157.0/120", "IN" ], [ "::1.22.158.0/119", "IN" ], [ "::1.22.160.0/119", "IN" ], [ "::1.22.162.0/120", "IN" ], [ "::1.22.163.0/120", "IN" ], [ "::1.22.164.0/120", "IN" ], [ "::1.22.165.0/120", "IN" ], [ "::1.22.166.0/119", "IN" ], [ "::1.22.168.0/119", "IN" ], [ "::1.22.170.0/119", "IN" ], [ "::1.22.172.0/120", "IN" ], [ "::1.22.173.0/120", "IN" ], [ "::1.22.174.0/119", "IN" ], [ "::1.22.176.0/120", "IN" ], [ "::1.22.177.0/120", "IN" ], [ "::1.22.178.0/119", "IN" ], [ "::1.22.180.0/118", "IN" ], [ "::1.22.184.0/121", "IN" ], [ "::1.22.184.128/122", "IN" ], [ "::1.22.184.192/122", "IN" ], [ "::1.22.185.0/120", "IN" ], [ "::1.22.186.0/119", "IN" ], [ "::1.22.188.0/119", "IN" ], [ "::1.22.190.0/119", "IN" ], [ "::1.22.192.0/119", "IN" ], [ "::1.22.194.0/119", "IN" ], [ "::1.22.196.0/119", "IN" ], [ "::1.22.198.0/119", "IN" ], [ "::1.22.200.0/120", "IN" ], [ "::1.22.201.0/120", "IN" ], [ "::1.22.202.0/120", "IN" ], [ "::1.22.203.0/120", "IN" ], [ "::1.22.204.0/120", "IN" ], [ "::1.22.205.0/120", "IN" ], [ "::1.22.206.0/119", "IN" ], [ "::1.22.208.0/118", "IN" ], [ "::1.22.212.0/119", "IN" ], [ "::1.22.214.0/119", "IN" ], [ "::1.22.216.0/119", "IN" ], [ "::1.22.218.0/120", "IN" ], [ "::1.22.219.0/120", "IN" ], [ "::1.22.220.0/120", "IN" ], [ "::1.22.221.0/120", "IN" ], [ "::1.22.222.0/119", "IN" ], [ "::1.22.224.0/119", "IN" ], [ "::1.22.226.0/120", "IN" ], [ "::1.22.227.0/120", "IN" ], [ "::1.22.228.0/120", "IN" ], [ "::1.22.229.0/120", "IN" ], [ "::1.22.230.0/119", "IN" ], [ "::1.22.232.0/119", "IN" ], [ "::1.22.234.0/119", "IN" ], [ "::1.22.236.0/120", "IN" ], [ "::1.22.237.0/120", "IN" ], [ "::1.22.238.0/120", "IN" ], [ "::1.22.239.0/120", "IN" ], [ "::1.22.240.0/120", "IN" ], [ "::1.22.241.0/120", "IN" ], [ "::1.22.242.0/119", "IN" ], [ "::1.22.244.0/118", "IN" ], [ "::1.22.248.0/117", "IN" ], [ "::1.23.0.0/116", "IN" ], [ "::1.23.16.0/116", "IN" ], [ "::1.23.32.0/118", "IN" ], [ "::1.23.36.0/118", "IN" ], [ "::1.23.40.0/118", "IN" ], [ "::1.23.44.0/120", "IN" ], [ "::1.23.45.0/120", "IN" ], [ "::1.23.46.0/119", "IN" ], [ "::1.23.48.0/117", "IN" ], [ "::1.23.56.0/119", "IN" ], [ "::1.23.58.0/119", "IN" ], [ "::1.23.60.0/118", "IN" ], [ "::1.23.64.0/117", "IN" ], [ "::1.23.72.0/117", "IN" ], [ "::1.23.80.0/118", "IN" ], [ "::1.23.84.0/119", "IN" ], [ "::1.23.86.0/121", "IN" ], [ "::1.23.86.128/121", "IN" ], [ "::1.23.87.0/120", "IN" ], [ "::1.23.88.0/118", "IN" ], [ "::1.23.92.0/119", "IN" ], [ "::1.23.94.0/119", "IN" ], [ "::1.23.96.0/120", "IN" ], [ "::1.23.97.0/120", "IN" ], [ "::1.23.98.0/120", "IN" ], [ "::1.23.99.0/120", "IN" ], [ "::1.23.100.0/120", "IN" ], [ "::1.23.101.0/120", "IN" ], [ "::1.23.102.0/119", "IN" ], [ "::1.23.104.0/117", "IN" ], [ "::1.23.112.0/119", "IN" ], [ "::1.23.114.0/120", "IN" ], [ "::1.23.115.0/120", "IN" ], [ "::1.23.116.0/120", "IN" ], [ "::1.23.117.0/120", "IN" ], [ "::1.23.118.0/119", "IN" ], [ "::1.23.120.0/120", "IN" ], [ "::1.23.121.0/120", "IN" ], [ "::1.23.122.0/119", "IN" ], [ "::1.23.124.0/118", "IN" ], [ "::1.23.128.0/115", "IN" ], [ "::1.23.160.0/119", "IN" ], [ "::1.23.162.0/119", "IN" ], [ "::1.23.164.0/119", "IN" ], [ "::1.23.166.0/119", "IN" ], [ "::1.23.168.0/119", "IN" ], [ "::1.23.170.0/119", "IN" ], [ "::1.23.172.0/118", "IN" ], [ "::1.23.176.0/116", "IN" ], [ "::1.23.192.0/119", "IN" ], [ "::1.23.194.0/119", "IN" ], [ "::1.23.196.0/120", "IN" ], [ "::1.23.197.0/120", "IN" ], [ "::1.23.198.0/119", "IN" ], [ "::1.23.200.0/118", "IN" ], [ "::1.23.204.0/120", "IN" ], [ "::1.23.205.0/120", "IN" ], [ "::1.23.206.0/119", "IN" ], [ "::1.23.208.0/119", "IN" ], [ "::1.23.210.0/120", "IN" ], [ "::1.23.211.0/120", "IN" ], [ "::1.23.212.0/119", "IN" ], [ "::1.23.214.0/119", "IN" ], [ "::1.23.216.0/119", "IN" ], [ "::1.23.218.0/119", "IN" ], [ "::1.23.220.0/119", "IN" ], [ "::1.23.222.0/119", "IN" ], [ "::1.23.224.0/118", "IN" ], [ "::1.23.228.0/119", "IN" ], [ "::1.23.230.0/119", "IN" ], [ "::1.23.232.0/119", "IN" ], [ "::1.23.234.0/120", "IN" ], [ "::1.23.235.0/120", "IN" ], [ "::1.23.236.0/120", "IN" ], [ "::1.23.237.0/120", "IN" ], [ "::1.23.238.0/119", "IN" ], [ "::1.23.240.0/118", "IN" ], [ "::1.23.244.0/119", "IN" ], [ "::1.23.246.0/120", "IN" ], [ "::1.23.247.0/120", "IN" ], [ "::1.23.248.0/120", "IN" ], [ "::1.23.249.0/120", "IN" ], [ "::1.23.250.0/120", "IN" ], [ "::1.23.251.0/120", "IN" ], [ "::1.23.252.0/120", "IN" ], [ "::1.23.253.0/120", "IN" ], [ "::1.23.254.0/119", "IN" ], [ "::1.24.0.0/112", "CN" ], [ "::1.25.0.0/117", "CN" ], [ "::1.25.8.0/119", "CN" ], [ "::1.25.10.0/120", "CN" ], [ "::1.25.11.0/120", "CN" ], [ "::1.25.12.0/118", "CN" ], [ "::1.25.16.0/116", "CN" ], [ "::1.25.32.0/115", "CN" ], [ "::1.25.64.0/114", "CN" ], [ "::1.25.128.0/113", "CN" ], [ "::1.26.0.0/111", "CN" ], [ "::1.28.0.0/110", "CN" ], [ "::1.32.0.0/112", "HK" ], [ "::1.33.0.0/120", "JP" ], [ "::1.33.1.0/120", "JP" ], [ "::1.33.2.0/119", "JP" ], [ "::1.33.4.0/118", "JP" ], [ "::1.33.8.0/117", "JP" ], [ "::1.33.16.0/116", "JP" ], [ "::1.33.32.0/117", "JP" ], [ "::1.33.40.0/118", "JP" ], [ "::1.33.44.0/120", "JP" ], [ "::1.33.45.0/120", "JP" ], [ "::1.33.46.0/119", "JP" ], [ "::1.33.48.0/116", "JP" ], [ "::1.33.64.0/119", "JP" ], [ "::1.33.66.0/119", "JP" ], [ "::1.33.68.0/119", "JP" ], [ "::1.33.70.0/120", "JP" ], [ "::1.33.71.0/120", "JP" ], [ "::1.33.72.0/117", "JP" ], [ "::1.33.80.0/116", "JP" ], [ "::1.33.96.0/117", "JP" ], [ "::1.33.104.0/119", "JP" ], [ "::1.33.106.0/120", "JP" ], [ "::1.33.107.0/120", "JP" ], [ "::1.33.108.0/118", "JP" ], [ "::1.33.112.0/116", "JP" ], [ "::1.33.128.0/114", "JP" ], [ "::1.33.192.0/116", "JP" ], [ "::1.33.208.0/119", "JP" ], [ "::1.33.210.0/120", "JP" ], [ "::1.33.211.0/121", "JP" ], [ "::1.33.211.128/121", "JP" ], [ "::1.33.212.0/118", "JP" ], [ "::1.33.216.0/117", "JP" ], [ "::1.33.224.0/118", "JP" ], [ "::1.33.228.0/119", "JP" ], [ "::1.33.230.0/120", "JP" ], [ "::1.33.231.0/120", "JP" ], [ "::1.33.232.0/117", "JP" ], [ "::1.33.240.0/117", "JP" ], [ "::1.33.248.0/120", "JP" ], [ "::1.33.249.0/120", "JP" ], [ "::1.33.250.0/119", "JP" ], [ "::1.33.252.0/118", "JP" ], [ "::1.34.0.0/116", "TW" ], [ "::1.34.16.0/119", "TW" ], [ "::1.34.18.0/120", "TW" ], [ "::1.34.19.0/120", "TW" ], [ "::1.34.20.0/118", "TW" ], [ "::1.34.24.0/117", "TW" ], [ "::1.34.32.0/115", "TW" ], [ "::1.34.64.0/116", "TW" ], [ "::1.34.80.0/117", "TW" ], [ "::1.34.88.0/118", "TW" ], [ "::1.34.92.0/120", "TW" ], [ "::1.34.93.0/120", "TW" ], [ "::1.34.94.0/119", "TW" ], [ "::1.34.96.0/120", "TW" ], [ "::1.34.97.0/120", "TW" ], [ "::1.34.98.0/119", "TW" ], [ "::1.34.100.0/118", "TW" ], [ "::1.34.104.0/117", "TW" ], [ "::1.34.112.0/116", "TW" ], [ "::1.34.128.0/113", "TW" ], [ "::1.35.0.0/112", "TW" ], [ "::1.36.0.0/120", "HK" ], [ "::1.36.1.0/120", "HK" ], [ "::1.36.2.0/120", "HK" ], [ "::1.36.3.0/120", "HK" ], [ "::1.36.4.0/119", "HK" ], [ "::1.36.6.0/120", "HK" ], [ "::1.36.7.0/120", "HK" ], [ "::1.36.8.0/119", "HK" ], [ "::1.36.10.0/119", "HK" ], [ "::1.36.12.0/119", "HK" ], [ "::1.36.14.0/120", "HK" ], [ "::1.36.15.0/120", "HK" ], [ "::1.36.16.0/117", "HK" ], [ "::1.36.24.0/118", "HK" ], [ "::1.36.28.0/120", "HK" ], [ "::1.36.29.0/120", "HK" ], [ "::1.36.30.0/119", "HK" ], [ "::1.36.32.0/118", "HK" ], [ "::1.36.36.0/119", "HK" ], [ "::1.36.38.0/120", "HK" ], [ "::1.36.39.0/120", "HK" ], [ "::1.36.40.0/118", "HK" ], [ "::1.36.44.0/120", "HK" ], [ "::1.36.45.0/120", "HK" ], [ "::1.36.46.0/121", "HK" ], [ "::1.36.46.128/121", "HK" ], [ "::1.36.47.0/120", "HK" ], [ "::1.36.48.0/117", "HK" ], [ "::1.36.56.0/119", "HK" ], [ "::1.36.58.0/120", "HK" ], [ "::1.36.59.0/120", "HK" ], [ "::1.36.60.0/119", "HK" ], [ "::1.36.62.0/120", "HK" ], [ "::1.36.63.0/120", "HK" ], [ "::1.36.64.0/119", "HK" ], [ "::1.36.66.0/120", "HK" ], [ "::1.36.67.0/121", "HK" ], [ "::1.36.67.128/121", "HK" ], [ "::1.36.68.0/118", "HK" ], [ "::1.36.72.0/120", "HK" ], [ "::1.36.73.0/120", "HK" ], [ "::1.36.74.0/119", "HK" ], [ "::1.36.76.0/119", "HK" ], [ "::1.36.78.0/120", "HK" ], [ "::1.36.79.0/120", "HK" ], [ "::1.36.80.0/118", "HK" ], [ "::1.36.84.0/120", "HK" ], [ "::1.36.85.0/120", "HK" ], [ "::1.36.86.0/119", "HK" ], [ "::1.36.88.0/120", "HK" ], [ "::1.36.89.0/120", "HK" ], [ "::1.36.90.0/120", "HK" ], [ "::1.36.91.0/120", "HK" ], [ "::1.36.92.0/118", "HK" ], [ "::1.36.96.0/116", "HK" ], [ "::1.36.112.0/117", "HK" ], [ "::1.36.120.0/120", "HK" ], [ "::1.36.121.0/120", "HK" ], [ "::1.36.122.0/119", "HK" ], [ "::1.36.124.0/120", "HK" ], [ "::1.36.125.0/120", "HK" ], [ "::1.36.126.0/119", "HK" ], [ "::1.36.128.0/120", "HK" ], [ "::1.36.129.0/120", "HK" ], [ "::1.36.130.0/119", "HK" ], [ "::1.36.132.0/118", "HK" ], [ "::1.36.136.0/117", "HK" ], [ "::1.36.144.0/117", "HK" ], [ "::1.36.152.0/118", "HK" ], [ "::1.36.156.0/119", "HK" ], [ "::1.36.158.0/120", "HK" ], [ "::1.36.159.0/120", "HK" ], [ "::1.36.160.0/116", "HK" ], [ "::1.36.176.0/118", "HK" ], [ "::1.36.180.0/120", "HK" ], [ "::1.36.181.0/120", "HK" ], [ "::1.36.182.0/119", "HK" ], [ "::1.36.184.0/117", "HK" ], [ "::1.36.192.0/117", "HK" ], [ "::1.36.200.0/119", "HK" ], [ "::1.36.202.0/120", "HK" ], [ "::1.36.203.0/120", "HK" ], [ "::1.36.204.0/118", "HK" ], [ "::1.36.208.0/119", "HK" ], [ "::1.36.210.0/120", "HK" ], [ "::1.36.211.0/120", "HK" ], [ "::1.36.212.0/118", "HK" ], [ "::1.36.216.0/120", "HK" ], [ "::1.36.217.0/120", "HK" ], [ "::1.36.218.0/120", "HK" ], [ "::1.36.219.0/120", "HK" ], [ "::1.36.220.0/120", "HK" ], [ "::1.36.221.0/120", "HK" ], [ "::1.36.222.0/119", "HK" ], [ "::1.36.224.0/116", "HK" ], [ "::1.36.240.0/117", "HK" ], [ "::1.36.248.0/119", "HK" ], [ "::1.36.250.0/120", "HK" ], [ "::1.36.251.0/120", "HK" ], [ "::1.36.252.0/118", "HK" ], [ "::1.37.0.0/112", "PH" ], [ "::1.38.0.0/117", "IN" ], [ "::1.38.8.0/118", "IN" ], [ "::1.38.12.0/120", "IN" ], [ "::1.38.13.0/127", "IN" ], [ "::1.38.13.2/127", "IN" ], [ "::1.38.13.4/126", "IN" ], [ "::1.38.13.8/125", "IN" ], [ "::1.38.13.16/124", "IN" ], [ "::1.38.13.32/123", "IN" ], [ "::1.38.13.64/122", "IN" ], [ "::1.38.13.128/121", "IN" ], [ "::1.38.14.0/120", "IN" ], [ "::1.38.15.0/120", "IN" ], [ "::1.38.16.0/122", "IN" ], [ "::1.38.16.64/122", "IN" ], [ "::1.38.16.128/122", "IN" ], [ "::1.38.16.192/122", "IN" ], [ "::1.38.17.0/120", "IN" ], [ "::1.38.18.0/119", "IN" ], [ "::1.38.20.0/120", "IN" ], [ "::1.38.21.0/120", "IN" ], [ "::1.38.22.0/120", "IN" ], [ "::1.38.23.0/122", "IN" ], [ "::1.38.23.64/123", "IN" ], [ "::1.38.23.96/123", "IN" ], [ "::1.38.23.128/121", "IN" ], [ "::1.38.24.0/123", "IN" ], [ "::1.38.24.32/125", "IN" ], [ "::1.38.24.40/125", "IN" ], [ "::1.38.24.48/124", "IN" ], [ "::1.38.24.64/123", "IN" ], [ "::1.38.24.96/123", "IN" ], [ "::1.38.24.128/121", "IN" ], [ "::1.38.25.0/124", "IN" ], [ "::1.38.25.16/125", "IN" ], [ "::1.38.25.24/125", "IN" ], [ "::1.38.25.32/125", "IN" ], [ "::1.38.25.40/125", "IN" ], [ "::1.38.25.48/124", "IN" ], [ "::1.38.25.64/124", "IN" ], [ "::1.38.25.80/124", "IN" ], [ "::1.38.25.96/123", "IN" ], [ "::1.38.25.128/121", "IN" ], [ "::1.38.26.0/121", "IN" ], [ "::1.38.26.128/121", "IN" ], [ "::1.38.27.0/121", "IN" ], [ "::1.38.27.128/122", "IN" ], [ "::1.38.27.192/122", "IN" ], [ "::1.38.28.0/122", "IN" ], [ "::1.38.28.64/125", "IN" ], [ "::1.38.28.72/125", "IN" ], [ "::1.38.28.80/124", "IN" ], [ "::1.38.28.96/125", "IN" ], [ "::1.38.28.104/126", "IN" ], [ "::1.38.28.108/126", "IN" ], [ "::1.38.28.112/124", "IN" ], [ "::1.38.28.128/121", "IN" ], [ "::1.38.29.0/120", "IN" ], [ "::1.38.30.0/123", "IN" ], [ "::1.38.30.32/126", "IN" ], [ "::1.38.30.36/126", "IN" ], [ "::1.38.30.40/125", "IN" ], [ "::1.38.30.48/124", "IN" ], [ "::1.38.30.64/122", "IN" ], [ "::1.38.30.128/121", "IN" ], [ "::1.38.31.0/121", "IN" ], [ "::1.38.31.128/121", "IN" ], [ "::1.38.32.0/118", "IN" ], [ "::1.38.36.0/119", "IN" ], [ "::1.38.38.0/120", "IN" ], [ "::1.38.39.0/120", "IN" ], [ "::1.38.40.0/117", "IN" ], [ "::1.38.48.0/116", "IN" ], [ "::1.38.64.0/117", "IN" ], [ "::1.38.72.0/118", "IN" ], [ "::1.38.76.0/120", "IN" ], [ "::1.38.77.0/120", "IN" ], [ "::1.38.78.0/119", "IN" ], [ "::1.38.80.0/116", "IN" ], [ "::1.38.96.0/120", "IN" ], [ "::1.38.97.0/120", "IN" ], [ "::1.38.98.0/119", "IN" ], [ "::1.38.100.0/118", "IN" ], [ "::1.38.104.0/117", "IN" ], [ "::1.38.112.0/117", "IN" ], [ "::1.38.120.0/120", "IN" ], [ "::1.38.121.0/120", "IN" ], [ "::1.38.122.0/119", "IN" ], [ "::1.38.124.0/118", "IN" ], [ "::1.38.128.0/114", "IN" ], [ "::1.38.192.0/115", "IN" ], [ "::1.38.224.0/117", "IN" ], [ "::1.38.232.0/120", "IN" ], [ "::1.38.233.0/120", "IN" ], [ "::1.38.234.0/119", "IN" ], [ "::1.38.236.0/118", "IN" ], [ "::1.38.240.0/116", "IN" ], [ "::1.39.0.0/115", "IN" ], [ "::1.39.32.0/116", "IN" ], [ "::1.39.48.0/117", "IN" ], [ "::1.39.56.0/119", "IN" ], [ "::1.39.58.0/120", "IN" ], [ "::1.39.59.0/120", "IN" ], [ "::1.39.60.0/118", "IN" ], [ "::1.39.64.0/114", "IN" ], [ "::1.39.128.0/113", "IN" ], [ "::1.40.0.0/110", "AU" ], [ "::1.44.0.0/120", "AU" ], [ "::1.44.1.0/120", "AU" ], [ "::1.44.2.0/119", "AU" ], [ "::1.44.4.0/120", "AU" ], [ "::1.44.5.0/120", "AU" ], [ "::1.44.6.0/120", "AU" ], [ "::1.44.7.0/120", "AU" ], [ "::1.44.8.0/120", "AU" ], [ "::1.44.9.0/120", "AU" ], [ "::1.44.10.0/119", "AU" ], [ "::1.44.12.0/120", "AU" ], [ "::1.44.13.0/120", "AU" ], [ "::1.44.14.0/120", "AU" ], [ "::1.44.15.0/120", "AU" ], [ "::1.44.16.0/120", "AU" ], [ "::1.44.17.0/120", "AU" ], [ "::1.44.18.0/119", "AU" ], [ "::1.44.20.0/119", "AU" ], [ "::1.44.22.0/120", "AU" ], [ "::1.44.23.0/120", "AU" ], [ "::1.44.24.0/119", "AU" ], [ "::1.44.26.0/120", "AU" ], [ "::1.44.27.0/120", "AU" ], [ "::1.44.28.0/119", "AU" ], [ "::1.44.30.0/120", "AU" ], [ "::1.44.31.0/120", "AU" ], [ "::1.44.32.0/118", "AU" ], [ "::1.44.36.0/120", "AU" ], [ "::1.44.37.0/120", "AU" ], [ "::1.44.38.0/119", "AU" ], [ "::1.44.40.0/120", "AU" ], [ "::1.44.41.0/120", "AU" ], [ "::1.44.42.0/119", "AU" ], [ "::1.44.44.0/120", "AU" ], [ "::1.44.45.0/120", "AU" ], [ "::1.44.46.0/120", "AU" ], [ "::1.44.47.0/120", "AU" ], [ "::1.44.48.0/120", "AU" ], [ "::1.44.49.0/120", "AU" ], [ "::1.44.50.0/119", "AU" ], [ "::1.44.52.0/120", "AU" ], [ "::1.44.53.0/120", "AU" ], [ "::1.44.54.0/120", "AU" ], [ "::1.44.55.0/120", "AU" ], [ "::1.44.56.0/118", "AU" ], [ "::1.44.60.0/119", "AU" ], [ "::1.44.62.0/120", "AU" ], [ "::1.44.63.0/120", "AU" ], [ "::1.44.64.0/120", "AU" ], [ "::1.44.65.0/120", "AU" ], [ "::1.44.66.0/119", "AU" ], [ "::1.44.68.0/119", "AU" ], [ "::1.44.70.0/120", "AU" ], [ "::1.44.71.0/120", "AU" ], [ "::1.44.72.0/120", "AU" ], [ "::1.44.73.0/120", "AU" ], [ "::1.44.74.0/119", "AU" ], [ "::1.44.76.0/119", "AU" ], [ "::1.44.78.0/120", "AU" ], [ "::1.44.79.0/120", "AU" ], [ "::1.44.80.0/120", "AU" ], [ "::1.44.81.0/120", "AU" ], [ "::1.44.82.0/119", "AU" ], [ "::1.44.84.0/119", "AU" ], [ "::1.44.86.0/120", "AU" ], [ "::1.44.87.0/120", "AU" ], [ "::1.44.88.0/120", "AU" ], [ "::1.44.89.0/120", "AU" ], [ "::1.44.90.0/120", "AU" ], [ "::1.44.91.0/120", "AU" ], [ "::1.44.92.0/120", "AU" ], [ "::1.44.93.0/120", "AU" ], [ "::1.44.94.0/120", "AU" ], [ "::1.44.95.0/120", "AU" ], [ "::1.44.96.0/120", "AU" ], [ "::1.44.97.0/120", "AU" ], [ "::1.44.98.0/119", "AU" ], [ "::1.44.100.0/120", "AU" ], [ "::1.44.101.0/120", "AU" ], [ "::1.44.102.0/119", "AU" ], [ "::1.44.104.0/120", "AU" ], [ "::1.44.105.0/120", "AU" ], [ "::1.44.106.0/120", "AU" ], [ "::1.44.107.0/120", "AU" ], [ "::1.44.108.0/120", "AU" ], [ "::1.44.109.0/120", "AU" ], [ "::1.44.110.0/120", "AU" ], [ "::1.44.111.0/120", "AU" ], [ "::1.44.112.0/120", "AU" ], [ "::1.44.113.0/120", "AU" ], [ "::1.44.114.0/119", "AU" ], [ "::1.44.116.0/120", "AU" ], [ "::1.44.117.0/120", "AU" ], [ "::1.44.118.0/120", "AU" ], [ "::1.44.119.0/120", "AU" ], [ "::1.44.120.0/119", "AU" ], [ "::1.44.122.0/120", "AU" ], [ "::1.44.123.0/120", "AU" ], [ "::1.44.124.0/119", "AU" ], [ "::1.44.126.0/120", "AU" ], [ "::1.44.127.0/120", "AU" ], [ "::1.44.128.0/119", "AU" ], [ "::1.44.130.0/119", "AU" ], [ "::1.44.132.0/118", "AU" ], [ "::1.44.136.0/120", "AU" ], [ "::1.44.137.0/120", "AU" ], [ "::1.44.138.0/119", "AU" ], [ "::1.44.140.0/119", "AU" ], [ "::1.44.142.0/120", "AU" ], [ "::1.44.143.0/120", "AU" ], [ "::1.44.144.0/120", "AU" ], [ "::1.44.145.0/120", "AU" ], [ "::1.44.146.0/120", "AU" ], [ "::1.44.147.0/120", "AU" ], [ "::1.44.148.0/119", "AU" ], [ "::1.44.150.0/120", "AU" ], [ "::1.44.151.0/120", "AU" ], [ "::1.44.152.0/120", "AU" ], [ "::1.44.153.0/120", "AU" ], [ "::1.44.154.0/120", "AU" ], [ "::1.44.155.0/120", "AU" ], [ "::1.44.156.0/120", "AU" ], [ "::1.44.157.0/120", "AU" ], [ "::1.44.158.0/120", "AU" ], [ "::1.44.159.0/120", "AU" ], [ "::1.44.160.0/120", "AU" ], [ "::1.44.161.0/120", "AU" ], [ "::1.44.162.0/120", "AU" ], [ "::1.44.163.0/120", "AU" ], [ "::1.44.164.0/120", "AU" ], [ "::1.44.165.0/120", "AU" ], [ "::1.44.166.0/119", "AU" ], [ "::1.44.168.0/120", "AU" ], [ "::1.44.169.0/120", "AU" ], [ "::1.44.170.0/120", "AU" ], [ "::1.44.171.0/120", "AU" ], [ "::1.44.172.0/119", "AU" ], [ "::1.44.174.0/120", "AU" ], [ "::1.44.175.0/120", "AU" ], [ "::1.44.176.0/120", "AU" ], [ "::1.44.177.0/120", "AU" ], [ "::1.44.178.0/120", "AU" ], [ "::1.44.179.0/120", "AU" ], [ "::1.44.180.0/120", "AU" ], [ "::1.44.181.0/120", "AU" ], [ "::1.44.182.0/119", "AU" ], [ "::1.44.184.0/120", "AU" ], [ "::1.44.185.0/120", "AU" ], [ "::1.44.186.0/120", "AU" ], [ "::1.44.187.0/120", "AU" ], [ "::1.44.188.0/120", "AU" ], [ "::1.44.189.0/120", "AU" ], [ "::1.44.190.0/119", "AU" ], [ "::1.44.192.0/119", "AU" ], [ "::1.44.194.0/120", "AU" ], [ "::1.44.195.0/120", "AU" ], [ "::1.44.196.0/119", "AU" ], [ "::1.44.198.0/120", "AU" ], [ "::1.44.199.0/120", "AU" ], [ "::1.44.200.0/120", "AU" ], [ "::1.44.201.0/120", "AU" ], [ "::1.44.202.0/119", "AU" ], [ "::1.44.204.0/120", "AU" ], [ "::1.44.205.0/120", "AU" ], [ "::1.44.206.0/120", "AU" ], [ "::1.44.207.0/120", "AU" ], [ "::1.44.208.0/120", "AU" ], [ "::1.44.209.0/120", "AU" ], [ "::1.44.210.0/120", "AU" ], [ "::1.44.211.0/120", "AU" ], [ "::1.44.212.0/119", "AU" ], [ "::1.44.214.0/120", "AU" ], [ "::1.44.215.0/120", "AU" ], [ "::1.44.216.0/119", "AU" ], [ "::1.44.218.0/119", "AU" ], [ "::1.44.220.0/120", "AU" ], [ "::1.44.221.0/120", "AU" ], [ "::1.44.222.0/120", "AU" ], [ "::1.44.223.0/120", "AU" ], [ "::1.44.224.0/120", "AU" ], [ "::1.44.225.0/120", "AU" ], [ "::1.44.226.0/119", "AU" ], [ "::1.44.228.0/120", "AU" ], [ "::1.44.229.0/120", "AU" ], [ "::1.44.230.0/120", "AU" ], [ "::1.44.231.0/120", "AU" ], [ "::1.44.232.0/120", "AU" ], [ "::1.44.233.0/120", "AU" ], [ "::1.44.234.0/120", "AU" ], [ "::1.44.235.0/120", "AU" ], [ "::1.44.236.0/120", "AU" ], [ "::1.44.237.0/120", "AU" ], [ "::1.44.238.0/120", "AU" ], [ "::1.44.239.0/120", "AU" ], [ "::1.44.240.0/120", "AU" ], [ "::1.44.241.0/120", "AU" ], [ "::1.44.242.0/119", "AU" ], [ "::1.44.244.0/118", "AU" ], [ "::1.44.248.0/120", "AU" ], [ "::1.44.249.0/120", "AU" ], [ "::1.44.250.0/119", "AU" ], [ "::1.44.252.0/120", "AU" ], [ "::1.44.253.0/120", "AU" ], [ "::1.44.254.0/120", "AU" ], [ "::1.44.255.0/120", "AU" ], [ "::1.45.0.0/112", "CN" ], [ "::1.46.0.0/111", "TH" ], [ "::1.48.0.0/111", "CN" ], [ "::1.50.0.0/112", "CN" ], [ "::1.51.0.0/115", "CN" ], [ "::1.51.32.0/116", "CN" ], [ "::1.51.48.0/117", "CN" ], [ "::1.51.56.0/117", "CN" ], [ "::1.51.64.0/114", "CN" ], [ "::1.51.128.0/116", "CN" ], [ "::1.51.144.0/116", "CN" ], [ "::1.51.160.0/116", "CN" ], [ "::1.51.176.0/116", "CN" ], [ "::1.51.192.0/114", "CN" ], [ "::1.52.0.0/128", "VN" ], [ "::1.52.0.1/128", "VN" ], [ "::1.52.0.2/127", "VN" ], [ "::1.52.0.4/126", "VN" ], [ "::1.52.0.8/125", "VN" ], [ "::1.52.0.16/124", "VN" ], [ "::1.52.0.32/123", "VN" ], [ "::1.52.0.64/122", "VN" ], [ "::1.52.0.128/121", "VN" ], [ "::1.52.1.0/120", "VN" ], [ "::1.52.2.0/119", "VN" ], [ "::1.52.4.0/118", "VN" ], [ "::1.52.8.0/117", "VN" ], [ "::1.52.16.0/116", "VN" ], [ "::1.52.32.0/115", "VN" ], [ "::1.52.64.0/116", "VN" ], [ "::1.52.80.0/116", "VN" ], [ "::1.52.96.0/116", "VN" ], [ "::1.52.112.0/120", "VN" ], [ "::1.52.113.0/120", "VN" ], [ "::1.52.114.0/119", "VN" ], [ "::1.52.116.0/120", "VN" ], [ "::1.52.117.0/120", "VN" ], [ "::1.52.118.0/119", "VN" ], [ "::1.52.120.0/117", "VN" ], [ "::1.52.128.0/115", "VN" ], [ "::1.52.160.0/119", "VN" ], [ "::1.52.162.0/120", "VN" ], [ "::1.52.163.0/120", "VN" ], [ "::1.52.164.0/118", "VN" ], [ "::1.52.168.0/117", "VN" ], [ "::1.52.176.0/116", "VN" ], [ "::1.52.192.0/115", "VN" ], [ "::1.52.224.0/116", "VN" ], [ "::1.52.240.0/116", "VN" ], [ "::1.53.0.0/117", "VN" ], [ "::1.53.8.0/119", "VN" ], [ "::1.53.10.0/120", "VN" ], [ "::1.53.11.0/120", "VN" ], [ "::1.53.12.0/120", "VN" ], [ "::1.53.13.0/120", "VN" ], [ "::1.53.14.0/119", "VN" ], [ "::1.53.16.0/118", "VN" ], [ "::1.53.20.0/120", "VN" ], [ "::1.53.21.0/120", "VN" ], [ "::1.53.22.0/120", "VN" ], [ "::1.53.23.0/120", "VN" ], [ "::1.53.24.0/120", "VN" ], [ "::1.53.25.0/120", "VN" ], [ "::1.53.26.0/120", "VN" ], [ "::1.53.27.0/120", "VN" ], [ "::1.53.28.0/118", "VN" ], [ "::1.53.32.0/116", "VN" ], [ "::1.53.48.0/120", "VN" ], [ "::1.53.49.0/120", "VN" ], [ "::1.53.50.0/119", "VN" ], [ "::1.53.52.0/118", "VN" ], [ "::1.53.56.0/117", "VN" ], [ "::1.53.64.0/119", "VN" ], [ "::1.53.66.0/120", "VN" ], [ "::1.53.67.0/120", "VN" ], [ "::1.53.68.0/118", "VN" ], [ "::1.53.72.0/118", "VN" ], [ "::1.53.76.0/120", "VN" ], [ "::1.53.77.0/120", "VN" ], [ "::1.53.78.0/119", "VN" ], [ "::1.53.80.0/116", "VN" ], [ "::1.53.96.0/119", "VN" ], [ "::1.53.98.0/120", "VN" ], [ "::1.53.99.0/120", "VN" ], [ "::1.53.100.0/118", "VN" ], [ "::1.53.104.0/117", "VN" ], [ "::1.53.112.0/116", "VN" ], [ "::1.53.128.0/116", "VN" ], [ "::1.53.144.0/116", "VN" ], [ "::1.53.160.0/119", "VN" ], [ "::1.53.162.0/120", "VN" ], [ "::1.53.163.0/120", "VN" ], [ "::1.53.164.0/119", "VN" ], [ "::1.53.166.0/119", "VN" ], [ "::1.53.168.0/117", "VN" ], [ "::1.53.176.0/116", "VN" ], [ "::1.53.192.0/118", "VN" ], [ "::1.53.196.0/120", "VN" ], [ "::1.53.197.0/120", "VN" ], [ "::1.53.198.0/119", "VN" ], [ "::1.53.200.0/117", "VN" ], [ "::1.53.208.0/116", "VN" ], [ "::1.53.224.0/118", "VN" ], [ "::1.53.228.0/120", "VN" ], [ "::1.53.229.0/120", "VN" ], [ "::1.53.230.0/119", "VN" ], [ "::1.53.232.0/117", "VN" ], [ "::1.53.240.0/116", "VN" ], [ "::1.54.0.0/117", "VN" ], [ "::1.54.8.0/119", "VN" ], [ "::1.54.10.0/120", "VN" ], [ "::1.54.11.0/120", "VN" ], [ "::1.54.12.0/120", "VN" ], [ "::1.54.13.0/120", "VN" ], [ "::1.54.14.0/121", "VN" ], [ "::1.54.14.128/121", "VN" ], [ "::1.54.15.0/120", "VN" ], [ "::1.54.16.0/118", "VN" ], [ "::1.54.20.0/118", "VN" ], [ "::1.54.24.0/120", "VN" ], [ "::1.54.25.0/120", "VN" ], [ "::1.54.26.0/120", "VN" ], [ "::1.54.27.0/120", "VN" ], [ "::1.54.28.0/118", "VN" ], [ "::1.54.32.0/115", "VN" ], [ "::1.54.64.0/117", "VN" ], [ "::1.54.72.0/119", "VN" ], [ "::1.54.74.0/119", "VN" ], [ "::1.54.76.0/118", "VN" ], [ "::1.54.80.0/120", "VN" ], [ "::1.54.81.0/120", "VN" ], [ "::1.54.82.0/119", "VN" ], [ "::1.54.84.0/120", "VN" ], [ "::1.54.85.0/120", "VN" ], [ "::1.54.86.0/119", "VN" ], [ "::1.54.88.0/117", "VN" ], [ "::1.54.96.0/120", "VN" ], [ "::1.54.97.0/120", "VN" ], [ "::1.54.98.0/119", "VN" ], [ "::1.54.100.0/118", "VN" ], [ "::1.54.104.0/117", "VN" ], [ "::1.54.112.0/120", "VN" ], [ "::1.54.113.0/120", "VN" ], [ "::1.54.114.0/120", "VN" ], [ "::1.54.115.0/120", "VN" ], [ "::1.54.116.0/119", "VN" ], [ "::1.54.118.0/120", "VN" ], [ "::1.54.119.0/120", "VN" ], [ "::1.54.120.0/117", "VN" ], [ "::1.54.128.0/119", "VN" ], [ "::1.54.130.0/120", "VN" ], [ "::1.54.131.0/120", "VN" ], [ "::1.54.132.0/118", "VN" ], [ "::1.54.136.0/117", "VN" ], [ "::1.54.144.0/119", "VN" ], [ "::1.54.146.0/120", "VN" ], [ "::1.54.147.0/120", "VN" ], [ "::1.54.148.0/118", "VN" ], [ "::1.54.152.0/117", "VN" ], [ "::1.54.160.0/119", "VN" ], [ "::1.54.162.0/120", "VN" ], [ "::1.54.163.0/120", "VN" ], [ "::1.54.164.0/118", "VN" ], [ "::1.54.168.0/118", "VN" ], [ "::1.54.172.0/120", "VN" ], [ "::1.54.173.0/120", "VN" ], [ "::1.54.174.0/119", "VN" ], [ "::1.54.176.0/116", "VN" ], [ "::1.54.192.0/116", "VN" ], [ "::1.54.208.0/120", "VN" ], [ "::1.54.209.0/120", "VN" ], [ "::1.54.210.0/119", "VN" ], [ "::1.54.212.0/118", "VN" ], [ "::1.54.216.0/117", "VN" ], [ "::1.54.224.0/115", "VN" ], [ "::1.55.0.0/121", "VN" ], [ "::1.55.0.128/122", "VN" ], [ "::1.55.0.192/123", "VN" ], [ "::1.55.0.224/128", "VN" ], [ "::1.55.0.225/128", "VN" ], [ "::1.55.0.226/127", "VN" ], [ "::1.55.0.228/126", "VN" ], [ "::1.55.0.232/125", "VN" ], [ "::1.55.0.240/124", "VN" ], [ "::1.55.1.0/120", "VN" ], [ "::1.55.2.0/120", "VN" ], [ "::1.55.3.0/120", "VN" ], [ "::1.55.4.0/118", "VN" ], [ "::1.55.8.0/119", "VN" ], [ "::1.55.10.0/120", "VN" ], [ "::1.55.11.0/120", "VN" ], [ "::1.55.12.0/118", "VN" ], [ "::1.55.16.0/116", "VN" ], [ "::1.55.32.0/119", "VN" ], [ "::1.55.34.0/120", "VN" ], [ "::1.55.35.0/120", "VN" ], [ "::1.55.36.0/118", "VN" ], [ "::1.55.40.0/117", "VN" ], [ "::1.55.48.0/117", "VN" ], [ "::1.55.56.0/120", "VN" ], [ "::1.55.57.0/120", "VN" ], [ "::1.55.58.0/120", "VN" ], [ "::1.55.59.0/120", "VN" ], [ "::1.55.60.0/118", "VN" ], [ "::1.55.64.0/114", "VN" ], [ "::1.55.128.0/118", "VN" ], [ "::1.55.132.0/119", "VN" ], [ "::1.55.134.0/120", "VN" ], [ "::1.55.135.0/120", "VN" ], [ "::1.55.136.0/117", "VN" ], [ "::1.55.144.0/116", "VN" ], [ "::1.55.160.0/116", "VN" ], [ "::1.55.176.0/120", "VN" ], [ "::1.55.177.0/121", "VN" ], [ "::1.55.177.128/121", "VN" ], [ "::1.55.178.0/119", "VN" ], [ "::1.55.180.0/119", "VN" ], [ "::1.55.182.0/120", "VN" ], [ "::1.55.183.0/120", "VN" ], [ "::1.55.184.0/117", "VN" ], [ "::1.55.192.0/115", "VN" ], [ "::1.55.224.0/116", "VN" ], [ "::1.55.240.0/116", "VN" ], [ "::1.56.0.0/111", "CN" ], [ "::1.58.0.0/115", "CN" ], [ "::1.58.32.0/119", "CN" ], [ "::1.58.34.0/120", "CN" ], [ "::1.58.35.0/120", "CN" ], [ "::1.58.36.0/118", "CN" ], [ "::1.58.40.0/117", "CN" ], [ "::1.58.48.0/116", "CN" ], [ "::1.58.64.0/114", "CN" ], [ "::1.58.128.0/113", "CN" ], [ "::1.59.0.0/112", "CN" ], [ "::1.60.0.0/110", "CN" ], [ "::1.64.0.0/117", "HK" ], [ "::1.64.8.0/120", "HK" ], [ "::1.64.9.0/121", "HK" ], [ "::1.64.9.128/121", "HK" ], [ "::1.64.10.0/120", "HK" ], [ "::1.64.11.0/120", "HK" ], [ "::1.64.12.0/118", "HK" ], [ "::1.64.16.0/118", "HK" ], [ "::1.64.20.0/119", "HK" ], [ "::1.64.22.0/120", "HK" ], [ "::1.64.23.0/120", "HK" ], [ "::1.64.24.0/118", "HK" ], [ "::1.64.28.0/120", "HK" ], [ "::1.64.29.0/120", "HK" ], [ "::1.64.30.0/119", "HK" ], [ "::1.64.32.0/117", "HK" ], [ "::1.64.40.0/119", "HK" ], [ "::1.64.42.0/120", "HK" ], [ "::1.64.43.0/120", "HK" ], [ "::1.64.44.0/118", "HK" ], [ "::1.64.48.0/117", "HK" ], [ "::1.64.56.0/121", "HK" ], [ "::1.64.56.128/121", "HK" ], [ "::1.64.57.0/120", "HK" ], [ "::1.64.58.0/119", "HK" ], [ "::1.64.60.0/118", "HK" ], [ "::1.64.64.0/115", "HK" ], [ "::1.64.96.0/118", "HK" ], [ "::1.64.100.0/120", "HK" ], [ "::1.64.101.0/120", "HK" ], [ "::1.64.102.0/119", "HK" ], [ "::1.64.104.0/120", "HK" ], [ "::1.64.105.0/120", "HK" ], [ "::1.64.106.0/120", "HK" ], [ "::1.64.107.0/120", "HK" ], [ "::1.64.108.0/118", "HK" ], [ "::1.64.112.0/116", "HK" ], [ "::1.64.128.0/116", "HK" ], [ "::1.64.144.0/119", "HK" ], [ "::1.64.146.0/119", "HK" ], [ "::1.64.148.0/118", "HK" ], [ "::1.64.152.0/117", "HK" ], [ "::1.64.160.0/119", "HK" ], [ "::1.64.162.0/120", "HK" ], [ "::1.64.163.0/120", "HK" ], [ "::1.64.164.0/118", "HK" ], [ "::1.64.168.0/119", "HK" ], [ "::1.64.170.0/120", "HK" ], [ "::1.64.171.0/120", "HK" ], [ "::1.64.172.0/118", "HK" ], [ "::1.64.176.0/120", "HK" ], [ "::1.64.177.0/120", "HK" ], [ "::1.64.178.0/119", "HK" ], [ "::1.64.180.0/120", "HK" ], [ "::1.64.181.0/120", "HK" ], [ "::1.64.182.0/119", "HK" ], [ "::1.64.184.0/117", "HK" ], [ "::1.64.192.0/119", "HK" ], [ "::1.64.194.0/120", "HK" ], [ "::1.64.195.0/121", "HK" ], [ "::1.64.195.128/121", "HK" ], [ "::1.64.196.0/118", "HK" ], [ "::1.64.200.0/117", "HK" ], [ "::1.64.208.0/120", "HK" ], [ "::1.64.209.0/120", "HK" ], [ "::1.64.210.0/119", "HK" ], [ "::1.64.212.0/118", "HK" ], [ "::1.64.216.0/118", "HK" ], [ "::1.64.220.0/120", "HK" ], [ "::1.64.221.0/120", "HK" ], [ "::1.64.222.0/119", "HK" ], [ "::1.64.224.0/116", "HK" ], [ "::1.64.240.0/120", "HK" ], [ "::1.64.241.0/120", "HK" ], [ "::1.64.242.0/119", "HK" ], [ "::1.64.244.0/118", "HK" ], [ "::1.64.248.0/117", "HK" ], [ "::1.65.0.0/112", "HK" ], [ "::1.66.0.0/111", "JP" ], [ "::1.68.0.0/110", "CN" ], [ "::1.72.0.0/117", "JP" ], [ "::1.72.8.0/120", "JP" ], [ "::1.72.9.0/120", "JP" ], [ "::1.72.10.0/119", "JP" ], [ "::1.72.12.0/118", "JP" ], [ "::1.72.16.0/116", "JP" ], [ "::1.72.32.0/115", "JP" ], [ "::1.72.64.0/115", "JP" ], [ "::1.72.96.0/116", "JP" ], [ "::1.72.112.0/120", "JP" ], [ "::1.72.113.0/120", "JP" ] ] Tree-bigint.t100644000000000000 216013321164704 22110 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writeruse strict; use warnings; use Test::Fatal; use Test::More 0.88; use MaxMind::DB::Writer::Tree; use Math::Int128 qw( uint128 ); use Net::Works::Address; use Net::Works::Network; { my $int128 = uint128(2) << 120; my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 4, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test tree' }, map_key_type_callback => sub { 'uint128' }, ); is( exception { $tree->insert_network( Net::Works::Network->new_from_string( string => '1.1.1.0/24' ), { value => $int128 }, ); }, undef, 'no exception inserting data that includes a Math::UInt128 object' ); my $ip_record = $tree->lookup_ip_address( Net::Works::Address->new_from_string( string => '1.1.1.1' ) ); is( $ip_record->{value}, $int128, 'got expected value back with Math::UInt128 object' ); } done_testing(); Serializer.pm100644000000000000 3427113321164704 22554 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/lib/MaxMind/DB/Writerpackage MaxMind::DB::Writer::Serializer; use strict; use warnings; use namespace::autoclean; our $VERSION = '0.300003'; require bytes; use Carp qw( confess ); use Data::IEEE754 qw( pack_double_be pack_float_be ); use Encode qw( encode is_utf8 FB_CROAK ); use Math::Int128 qw( uint128_to_net ); use MaxMind::DB::Common 0.031000 qw( %TypeNameToNum ); use MaxMind::DB::Writer::Util qw( key_for_data ); use Moose; use MooseX::StrictConstructor; with 'MaxMind::DB::Role::Debugs'; ## no critic (ValuesAndExpressions::ProhibitConstantPragma) use constant DEBUG => $ENV{MAXMIND_DB_SERIALIZER_DEBUG}; use constant VERIFY => $ENV{MAXMIND_DB_SERIALIZER_VERIFY}; if (VERIFY) { require MaxMind::DB::Reader::Decoder; require Test::Deep::NoTest; Test::Deep::NoTest->import(qw( cmp_details deep_diag )); } if (DEBUG) { binmode STDERR, ':encoding(UTF-8)' or die $!; } has buffer => ( is => 'ro', isa => 'ScalarRef[Str]', init_arg => undef, lazy => 1, default => sub { my $buffer = q{}; return \$buffer; }, ); has _map_key_type_callback => ( is => 'ro', isa => 'CodeRef', init_arg => 'map_key_type_callback', required => 1, ); # This is settable so we can more easily test the encoding portion of the code # without letting the deduplication interfere and turn a data item into a # pointer. In normal use this should always be true. has _deduplicate_data => ( is => 'ro', isa => 'Bool', default => 1, ); has _cache => ( traits => ['Hash'], is => 'ro', isa => 'HashRef', init_arg => undef, lazy => 1, default => sub { {} }, handles => { _save_position => 'set', _position_for_data => 'get', }, ); has _decoder => ( is => 'ro', isa => 'MaxMind::DB::Reader::Decoder', init_arg => undef, lazy => 1, builder => '_build_decoder', ); my $MinimumCacheableSize = 4; sub store_data { my $self = shift; my $type = shift; my $data = shift; my $member_type = shift; my $key_for_data = shift; confess 'Cannot store an undef as data' unless defined $data; $self->_debug_newline() if DEBUG; $self->_debug_string( 'Storing type', $type ) if DEBUG; return $self->_store_data( $type, $data, $member_type ) unless $self->_should_cache_value( $type, $data ); $key_for_data //= key_for_data($data); $self->_debug_string( 'Cache key', $key_for_data ) if DEBUG; my $position = $self->_position_for_data($key_for_data); if ( defined $position ) { if (DEBUG) { $self->_debug_string( 'Found data at position', $position ); $self->_debug_string( 'Storing pointer to', $position ); } return $self->_store_data( pointer => $position ); } else { my $stored_position = $self->_store_data( $type, $data, $member_type ); $self->_debug_string( 'Stored data at position', $stored_position ) if DEBUG; $self->_save_position( $key_for_data => $stored_position ); return $stored_position; } } if (VERIFY) { around store_data => sub { my $orig = shift; my $self = shift; my $type = shift; my $data = shift; my $member_type = shift; my $position = $self->$orig( $type, $data, $member_type ); my $stored_data = $self->_decoder()->decode($position); my ( $ok, $stack ) = cmp_details( $data, $stored_data ); unless ($ok) { my $diag = deep_diag($stack); die "Data we just stored does not decode to value we expected:\n$diag\n"; } return $position; }; } # These types never take more than 4 bytes to store. my %NeverCache = map { $_ => 1 } qw( int32 uint16 uint32 ); sub _should_cache_value { my $self = shift; my $type = shift; my $data = shift; return 0 unless $self->_deduplicate_data(); if ( $NeverCache{$type} ) { $self->_debug_string( 'Never cache type', $type ) if DEBUG; return 0; } if ( $type eq 'uint64' || $type eq 'uint128' ) { ( my $non_zero = $data ) =~ s/^0+//; my $stored_bytes = ( length($non_zero) / 4 ); $self->_debug_string( "Space needed for $type $data", $stored_bytes ) if DEBUG; # We can store four hex digits per byte. Once we strip leading zeros, # we know how much space this number will take to store. return $stored_bytes >= $MinimumCacheableSize; } elsif ( ref $data ) { $self->_debug_message('Always cache references') if DEBUG; return 1; } else { ## no critic (ProhibitCallsToUnexportedSubs) $self->_debug_string( "Space needed for $type $data", bytes::length $data ) if DEBUG; return bytes::length($data) >= $MinimumCacheableSize; } } sub _store_data { my $self = shift; my $type = shift; my $data = shift; my $member_type = shift; ## no critic (ProhibitCallsToUnexportedSubs) my $current_position = bytes::length ${ $self->buffer() }; my $method = '_encode_' . $type; $self->$method( $data, $member_type ); # We don't add 1 byte because the first byte we can point to is byte 0 # (not 1). return $current_position; } my @pointer_thresholds = ( { cutoff => 2**11, offset => 0, } ); push @pointer_thresholds, { cutoff => 2**19 + $pointer_thresholds[-1]{cutoff}, offset => $pointer_thresholds[-1]{cutoff}, }; push @pointer_thresholds, { cutoff => 2**27 + $pointer_thresholds[-1]{cutoff}, offset => $pointer_thresholds[-1]{cutoff}, }; push @pointer_thresholds, { cutoff => 2**32, offset => 0, }; ## no critic (ProhibitUnusedPrivateSubroutines) sub _encode_pointer { my $self = shift; my $value = shift; $self->_require_x_bits_unsigned_integer( 32, $value ); my $ctrl_byte = ord( $self->_control_bytes( $TypeNameToNum{pointer}, 0 ) ); my @value_bytes; for my $n ( 0 .. 3 ) { if ( $value < $pointer_thresholds[$n]{cutoff} ) { my $pack_method = '_pack_' . ( $n + 1 ) . '_byte_pointer'; @value_bytes = split //, $self->$pack_method( $value - $pointer_thresholds[$n]{offset} ); if ( $n == 3 ) { $ctrl_byte |= ( 3 << 3 ); } else { $ctrl_byte |= ( $n << 3 ) | ord( shift @value_bytes ); } last; } } $self->_write_encoded_data( pack( 'C', $ctrl_byte ), @value_bytes ); } sub _pack_1_byte_pointer { return pack( n => $_[1] ); } sub _pack_2_byte_pointer { return substr( pack( N => $_[1] ), 1, 3 ); } sub _pack_3_byte_pointer { return pack( N => $_[1] ); } sub _pack_4_byte_pointer { return pack( N => $_[1] ); } sub _encode_utf8_string { my $self = shift; my $string = shift; $self->_simple_encode( utf8_string => encode( 'UTF-8', $string, FB_CROAK ) ); } sub _encode_double { my $self = shift; $self->_write_encoded_data( $self->_control_bytes( $TypeNameToNum{double}, 8, ), pack_double_be(shift) ); } sub _encode_float { my $self = shift; $self->_write_encoded_data( $self->_control_bytes( $TypeNameToNum{float}, 4, ), pack_float_be(shift) ); } sub _encode_bytes { my $self = shift; my $bytes = shift; die "You attempted to store a characters string ($bytes) as bytes" if is_utf8($bytes); $self->_simple_encode( bytes => $bytes ); } sub _encode_uint16 { my $self = shift; $self->_encode_unsigned_int( 16 => @_ ); } sub _encode_uint32 { my $self = shift; $self->_encode_unsigned_int( 32 => @_ ); } sub _encode_map { my $self = shift; my $map = shift; $self->_write_encoded_data( $self->_control_bytes( $TypeNameToNum{map}, scalar keys %{$map} ) ); # We sort to make testing possible. for my $k ( sort keys %{$map} ) { $self->store_data( utf8_string => $k ); my $value_type = $self->_type_for_key( $k, $map->{$k} ); my $array_value_type; if ( ref $value_type ) { ( $value_type, $array_value_type ) = @{$value_type}; } $self->store_data( $value_type, $map->{$k}, $array_value_type ); } } sub _encode_array { my $self = shift; my $array = shift; my $value_type = shift; die 'No value type for array!' unless defined $value_type; $self->_write_encoded_data( $self->_control_bytes( $TypeNameToNum{array}, scalar @{$array} ) ); $self->store_data( $value_type, $_ ) for @{$array}; } sub _type_for_key { my $self = shift; my $key = shift; my $value = shift; my $type = $self->_map_key_type_callback->( $key, $value ); die qq{Could not determine the type for map key "$key"} unless $type; return $type; } sub _encode_int32 { my $self = shift; my $value = shift; my $encoded_value = pack( 'N!' => $value ); $encoded_value =~ s/^\x00+//; $self->_write_encoded_data( $self->_control_bytes( $TypeNameToNum{int32}, length($encoded_value) ), $encoded_value, ); } sub _encode_uint64 { my $self = shift; $self->_encode_unsigned_int( 64 => @_ ); } sub _encode_uint128 { my $self = shift; $self->_encode_unsigned_int( 128 => @_ ); } sub _encode_boolean { my $self = shift; my $value = shift; $self->_write_encoded_data( $self->_control_bytes( $TypeNameToNum{boolean}, $value ? 1 : 0 ) ); } sub _encode_end_marker { my $self = shift; $self->_simple_encode( 'end_marker', q{} ); } sub _simple_encode { my $self = shift; my $type = shift; my $value = shift; $self->_write_encoded_data( $self->_control_bytes( $TypeNameToNum{$type}, length($value) ), $value, ); } sub _encode_unsigned_int { my $self = shift; my $bits = shift; my $value = shift; $self->_require_x_bits_unsigned_integer( $bits, $value ); my $encoded_value; if ( $bits >= 64 ) { $encoded_value = uint128_to_net($value); } else { $encoded_value = pack( N => $value ); } $encoded_value =~ s/^\x00+//; $self->_write_encoded_data( $self->_control_bytes( $TypeNameToNum{ 'uint' . $bits }, length($encoded_value) ), $encoded_value, ); } ## use critic { my %Max = ( 16 => ( 2**16 ) - 1, 32 => ( 2**32 ) - 1, ); sub _require_x_bits_unsigned_integer { my $self = shift; my $bits = shift; my $value = shift; my $type_description = "unsigned $bits-bit integer"; die "You cannot encode undef as an $type_description." unless defined $value; if ( $bits >= 64 ) { if ( blessed $value && $value->isa('Math::UInt128') ) { die "You cannot encode $value as an $type_description. It is too big." if $bits != 128 && $value / ( 2**$bits ) > 1; } else { die "You cannot encode $value as an $type_description. It is not an unsigned integer number." unless $value =~ /^[0-9]+$/; } } else { die "You cannot encode $value as an $type_description. It is not an unsigned integer number." unless $value =~ /^[0-9]+$/; die "You cannot encode $value as an $type_description. It is too big." if $value > $Max{$bits}; } } } { # The value is the threshold for needing another byte to store the size # value. In other words, a size of 28 fits in one byte, a size of 29 needs # two bytes. my %ThresholdSize = ( 1 => 29, 2 => 29 + 256, 3 => 29 + 256 + 2**16, 4 => 29 + 256 + 2**16 + 2**24, ); sub _control_bytes { my $self = shift; my $type = shift; my $size = shift; if ( $size >= $ThresholdSize{4} ) { die "Cannot store $size bytes - max size is " . ( $ThresholdSize{4} - 1 ) . ' bytes'; } my $template = 'C'; my $first_byte; my $second_byte; if ( $type < 8 ) { $first_byte = ( $type << 5 ); } else { $first_byte = ( $TypeNameToNum{extended} << 5 ); $second_byte = $type - 7; $template .= 'C'; } my $leftover_size; ## no critic (ControlStructures::ProhibitCascadingIfElse) if ( $size < $ThresholdSize{1} ) { $first_byte |= $size; } elsif ( $size <= $ThresholdSize{2} ) { $first_byte |= 29; $leftover_size = $size - $ThresholdSize{1}; $template .= 'C'; } elsif ( $size <= $ThresholdSize{3} ) { $first_byte |= 30; $leftover_size = $size - $ThresholdSize{2}; $template .= 'n'; } elsif ( $size <= $ThresholdSize{4} ) { $first_byte |= 31; # There's no nice way to express "pack an integer into 24 bits" # using a pack template, so we'll just pack it here and then chop # off the first byte. $leftover_size = substr( pack( N => $size - $ThresholdSize{3} ), 1 ); $template .= 'a3'; } return pack( $template => grep { defined } ( $first_byte, $second_byte, $leftover_size, ) ); } } sub _write_encoded_data { my $self = shift; ${ $self->buffer() } .= $_ for @_; $self->_debug_binary( 'Wrote', join q{}, @_ ) if DEBUG; return; } sub _build_decoder { my $self = shift; ## no critic (InputOutput::RequireBriefOpen) open my $fh, '<:raw', $self->buffer() or die $!; return MaxMind::DB::Reader::Decoder->new( data_source => $fh, ); } __PACKAGE__->meta()->make_immutable(); 1; Tree-iterator.t100644000000000000 640613321164704 22474 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writeruse strict; use warnings; use lib 't/lib'; use Test::Fatal; use Test::MaxMind::DB::Writer qw( make_tree_from_pairs ranges_to_data test_iterator_sanity ); use Test::MaxMind::DB::Writer::Iterator (); use Test::More; my ( $insert, $expect ) = ranges_to_data( [ [ '1.1.1.1', '1.1.1.32' ], ], [ [ '1.1.1.1', '1.1.1.32' ], ], ); my $basic_tree = make_tree_from_pairs( 'network', $insert ); ## no critic (Modules::ProhibitMultiplePackages) { like( exception { $basic_tree->iterate( [] ) }, qr/\QThe argument passed to iterate (ARRAY(\E.+\Q)) is not an object or class name/, 'calling iterate() with a non object reference fails' ); { package Foo; } like( exception { $basic_tree->iterate( bless {}, 'Foo' ) }, qr/\QThe object or class passed to iterate must implement at least one method of process_empty_record, process_node_record, or process_data_record/, 'calling iterate() with a method-less object fails' ); like( exception { $basic_tree->iterate('Foo') }, qr/\QThe object or class passed to iterate must implement at least one method of process_empty_record, process_node_record, or process_data_record/, 'calling iterate() with a method-less class fails' ); { package Bar; sub process_empty_record { } } is( exception { $basic_tree->iterate( bless {}, 'Bar' ) }, undef, 'calling iterate() with an object with only a process_empty_record method succeeds' ); is( exception { $basic_tree->iterate('Bar') }, undef, 'calling iterate() with a class with process_empty_record method succeeds' ); } { my $iterator = Test::MaxMind::DB::Writer::Iterator->new(4); $basic_tree->iterate($iterator); test_iterator_sanity( $iterator, $basic_tree, 6, 'basic tree' ); is_deeply( [ sort { $a->{id} <=> $b->{id} } map { $_->[1] } @{ $iterator->{data_records} } ], [ sort { $a->{id} <=> $b->{id} } map { $_->[1] } @{$expect} ], 'saw expected data records - basic tree' ); my @data_record_networks = qw( 1.1.1.1/32 1.1.1.2/31 1.1.1.4/30 1.1.1.8/29 1.1.1.16/28 1.1.1.32/32 ); is_deeply( [ sort map { "$_->[0]" } @{ $iterator->{data_records} } ], [ sort @data_record_networks ], 'saw the expected networks for data records - basic tree' ); } { my $tree = make_tree_from_pairs( 'network', [ map { [ Net::Works::Network->new_from_string( string => $_ ) => { foo => 42 } ] } qw( ::1.0.0.0/120 2003::/96 abcd::1000/116 ) ], { alias_ipv6_to_ipv4 => 1 }, ); my $iterator = Test::MaxMind::DB::Writer::Iterator->new(6); $tree->iterate($iterator); test_iterator_sanity( $iterator, $tree, 3, 'aliased tree' ); my @data_record_networks = qw( ::1.0.0.0/120 2003::/96 abcd::1000/116 ); is_deeply( [ sort map { "$_->[0]" } @{ $iterator->{data_records} } ], [ sort @data_record_networks ], 'saw the expected networks for data records - aliased tree' ); } done_testing(); Tree-ipv4-and-6.t100644000000000000 156013321164704 22424 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writeruse strict; use warnings; use Test::Fatal; use Test::More; use MaxMind::DB::Writer::Tree; use Net::Works::Network; { my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 4, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test tree' }, map_key_type_callback => sub { }, ); my $expected = qr{You cannot insert an IPv6 address [(]::(?:0[.]0[.]0[.])?2[)] into an IPv4 tree.}; like( exception { $tree->insert_network( '::2/128', 'foo' ) }, $expected, q{Cannot insert an IPv6 network into an IPv4 tree} ); like( exception { $tree->insert_range( '::2', '::3', 'foo' ) }, $expected, q{Cannot insert an IPv6 range into an IPv4 tree} ); } done_testing(); Tree-thaw-merge.t100644000000000000 3151713321164704 22724 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writeruse strict; use warnings; use utf8; use autodie; use lib 't/lib'; use Test::Requires { JSON => 0, 'MaxMind::DB::Reader' => 0.040000, }; use File::Temp qw( tempdir ); use MaxMind::DB::Writer::Tree; use Net::Works::Network; use Test::More; use Test::Warnings qw( :all ); ######################################################################## # the purpose of this test is to check the merging arguments are being # set correctly and act correctly both on an original tree and a # thawed tree. This test doesn't fully check either freezing or thawing # or merging behavior - that's handled by other tests ######################################################################## # this is the IP range we'll be testing and an IP within it my $NETWORK = Net::Works::Network->new_from_string( string => '::0/1' ); my $IP_ADDRESS = '::123.123.123.123'; sub check_tree { my $name = shift; my $extra_constructor_args = shift; my $extra_thaw_args = shift; my $callback = shift; subtest( $name, sub { # we don't use TryTiny here because we're not otherwise depending on it return if eval { my $tree1 = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test tree' }, map_key_type_callback => sub { 'uint32' }, @{$extra_constructor_args}, ); $tree1->insert_network( $NETWORK, { value => 42 } ); my $dir = tempdir( CLEANUP => 1 ); my $file = "$dir/frozen-tree"; $tree1->freeze_tree($file); my $tree2 = MaxMind::DB::Writer::Tree->new_from_frozen_tree( filename => $file, map_key_type_callback => $tree1->map_key_type_callback(), @{$extra_thaw_args}, ); # attempt to stick a second value for the same IP range in both the # original and the restored thawed trees, to see what happens with # merging now $_->insert_network( $NETWORK, { leet => 1337 } ) for ( $tree1, $tree2 ); my ( $record1, $record2 ) = map { $_->lookup_ip_address($IP_ADDRESS) } ( $tree1, $tree2 ); $callback->( original_tree => $tree1, thawed_tree => $tree2, original_record => $record1, thawed_record => $record2, ); 1; }; # threw an exception, turn into failing test my $err = $@; ok( 0, 'Run without exceptions' ); diag($err); } ); } ######################################################################## # no merging ######################################################################## check_tree( 'check defaults work', [], [], sub { my %args = @_; like( warning { ok( !$args{thawed_tree}->merge_record_collisions, 'thawed merge_record_collisons' ) }, qr/merge_record_collisions is deprecated/, 'received deprecation message' ); is( $args{thawed_tree}->merge_strategy, 'none', 'thawed merge_strategy' ); is_deeply( $args{original_record}, { leet => 1337, }, 'check original record' ); is_deeply( $args{thawed_record}, { leet => 1337, }, 'check thawed record' ); } ); check_tree( 'check no merging explictly', [ merge_strategy => 'none' ], [], sub { my %args = @_; is( $args{thawed_tree}->merge_strategy, 'none', 'thawed merge_strategy' ); is_deeply( $args{original_record}, { leet => 1337, }, 'check original record' ); is_deeply( $args{thawed_record}, { leet => 1337, }, 'check thawed record' ); } ); check_tree( 'check no merging and none explictly', [ merge_strategy => 'none' ], [], sub { my %args = @_; is( $args{thawed_tree}->merge_strategy, 'none', 'thawed merge_strategy' ); is_deeply( $args{original_record}, { leet => 1337, }, 'check original record' ); is_deeply( $args{thawed_record}, { leet => 1337, }, 'check thawed record' ); } ); ######################################################################## # explictly merging in both cases ######################################################################## check_tree( 'set mrc in constructor, toplevel in thaw', [ merge_strategy => 'toplevel' ], [ merge_strategy => 'toplevel' ], sub { my %args = @_; like( warning { ok( $args{thawed_tree}->merge_record_collisions, 'thawed merge_record_collisons' ) }, qr/merge_record_collisions is deprecated/, 'received deprecation message' ); is( $args{thawed_tree}->merge_strategy, 'toplevel', 'thawed merge_strategy' ); is_deeply( $args{original_record}, { value => 42, leet => 1337, }, 'check original record' ); is_deeply( $args{thawed_record}, { value => 42, leet => 1337, }, 'check thawed record' ); } ); check_tree( 'set toplevel in constructor', [ merge_strategy => 'toplevel' ], [ merge_strategy => 'toplevel' ], sub { my %args = @_; is( $args{thawed_tree}->merge_strategy, 'toplevel', 'thawed merge_strategy' ); is_deeply( $args{original_record}, { value => 42, leet => 1337, }, 'check original record' ); is_deeply( $args{thawed_record}, { value => 42, leet => 1337, }, 'check thawed record' ); } ); check_tree( 'set recurse in constructor', [ merge_strategy => 'recurse' ], [ merge_strategy => 'recurse' ], sub { my %args = @_; is( $args{thawed_tree}->merge_strategy, 'recurse', 'thawed merge_strategy' ); is_deeply( $args{original_record}, { value => 42, leet => 1337, }, 'check original record' ); is_deeply( $args{thawed_record}, { value => 42, leet => 1337, }, 'check thawed record' ); } ); ######################################################################## # set just in constructore ######################################################################## check_tree( 'set mrc only in constructor', [ merge_strategy => 'toplevel' ], [], sub { my %args = @_; is( $args{thawed_tree}->merge_strategy, 'toplevel', 'thawed merge_strategy' ); is_deeply( $args{original_record}, { value => 42, leet => 1337, }, 'check original record' ); is_deeply( $args{thawed_record}, { value => 42, leet => 1337, }, 'check thawed record' ); } ); check_tree( 'set toplevel only in constructor', [ merge_strategy => 'toplevel' ], [], sub { my %args = @_; is( $args{thawed_tree}->merge_strategy, 'toplevel', 'thawed merge_strategy' ); is_deeply( $args{original_record}, { value => 42, leet => 1337, }, 'check original record' ); is_deeply( $args{thawed_record}, { value => 42, leet => 1337, }, 'check thawed record' ); } ); check_tree( 'set recurse only in constructor', [ merge_strategy => 'recurse' ], [], sub { my %args = @_; is( $args{thawed_tree}->merge_strategy, 'recurse', 'thawed merge_strategy' ); is_deeply( $args{original_record}, { value => 42, leet => 1337, }, 'check original record' ); is_deeply( $args{thawed_record}, { value => 42, leet => 1337, }, 'check thawed record' ); } ); ######################################################################## # set differing options in thaw ######################################################################## check_tree( 'set toplevel only in thaw', [], [ merge_strategy => 'toplevel' ], sub { my %args = @_; is( $args{thawed_tree}->merge_strategy, 'toplevel', 'thawed merge_strategy' ); is_deeply( $args{original_record}, { leet => 1337, }, 'check original record' ); is_deeply( $args{thawed_record}, { value => 42, leet => 1337, }, 'check thawed record' ); } ); check_tree( 'set mrc off in constructor, toplevel in thaw', [ merge_strategy => 'none' ], [ merge_strategy => 'toplevel' ], sub { my %args = @_; is( $args{thawed_tree}->merge_strategy, 'toplevel', 'thawed merge_strategy' ); is_deeply( $args{original_record}, { leet => 1337, }, 'check original record' ); is_deeply( $args{thawed_record}, { value => 42, leet => 1337, }, 'check thawed record' ); } ); check_tree( 'set none in constructor, toplevel only in thaw', [ merge_strategy => 'none' ], [ merge_strategy => 'toplevel' ], sub { my %args = @_; is( $args{thawed_tree}->merge_strategy, 'toplevel', 'thawed merge_strategy' ); is_deeply( $args{original_record}, { leet => 1337, }, 'check original record' ); is_deeply( $args{thawed_record}, { value => 42, leet => 1337, }, 'check thawed record' ); } ); check_tree( 'set recurse only in thaw', [], [ merge_strategy => 'recurse' ], sub { my %args = @_; is( $args{thawed_tree}->merge_strategy, 'recurse', 'thawed merge_strategy' ); is_deeply( $args{original_record}, { leet => 1337, }, 'check original record' ); is_deeply( $args{thawed_record}, { value => 42, leet => 1337, }, 'check thawed record' ); } ); check_tree( 'set mrc off in constructor, recurse in thaw', [ merge_strategy => 'none' ], [ merge_strategy => 'recurse' ], sub { my %args = @_; is( $args{thawed_tree}->merge_strategy, 'recurse', 'thawed merge_strategy' ); is_deeply( $args{original_record}, { leet => 1337, }, 'check original record' ); is_deeply( $args{thawed_record}, { value => 42, leet => 1337, }, 'check thawed record' ); } ); done_testing(); Tree-freeze-thaw.t100644000000000000 1501313321164704 23076 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writeruse strict; use warnings; use utf8; use autodie; use lib 't/lib'; use Test::Requires { JSON => 0, 'MaxMind::DB::Reader' => 0.040000, }; use Test::MaxMind::DB::Writer qw( make_tree_from_pairs test_freeze_thaw test_freeze_thaw_optional_params ); use Test::More; use File::Temp qw( tempdir ); use JSON (); use Math::Int128 qw( uint128 ); use MaxMind::DB::Reader (); use MaxMind::DB::Writer::Tree (); use Net::Works::Network (); # The record size really has nothing to do with the freeze/thaw code, but it # doesn't really hurt to test this either. for my $record_size ( 24, 28, 32 ) { { my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 4, record_size => $record_size, database_type => 'Test', languages => [ 'en', 'fr' ], description => { en => 'Test tree' }, merge_strategy => 'toplevel', map_key_type_callback => sub { 'uint32' }, # Below we try to insert into reserved space, which fails if we # flag them as fixed empty. remove_reserved_networks => 0, ); my $count = 2**8; for my $i ( 1 .. $count ) { my $ipv4 = Net::Works::Network->new_from_integer( integer => $i, prefix_length => 32, version => 4, ); $tree->insert_network( $ipv4, { i => $i } ); } subtest( "Tree with $count networks - IPv4 only - $record_size-bit records", sub { test_freeze_thaw($tree); test_freeze_thaw_optional_params($tree); } ); } { my $cb = sub { my $key = $_[0]; $key =~ s/X$//; return $key eq 'array' ? [ 'array', 'uint32' ] : $key; }; my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test tree' }, merge_strategy => 'toplevel', map_key_type_callback => $cb, # Below we try to insert into reserved space, which fails if we # flag them as fixed empty. remove_reserved_networks => 0, ); my $count = 2**14; my $ipv6_offset = uint128(2)**34; for my $i ( 1 .. $count ) { my $ipv4 = Net::Works::Network->new_from_integer( integer => $i, prefix_length => 128, version => 6 ); $tree->insert_network( $ipv4, _data_record( $i % 16 ) ); my $ipv6 = Net::Works::Network->new_from_integer( integer => $i + $ipv6_offset, prefix_length => 128, version => 6 ); $tree->insert_network( $ipv6, _data_record( $i % 16 ) ); } subtest( "Tree with $count networks - mixed IPv4 and IPv6 - $record_size-bit records", sub { test_freeze_thaw( $tree, $cb ); } ); } } { open my $fh, '<', 't/test-data/geolite2-sample.json' or die $!; my $geolite2_data = do { local $/ = undef; <$fh> }; my $records = JSON->new->decode($geolite2_data); close $fh or die $!; my $tree = make_tree_from_pairs( 'network', $records, { root_data_type => 'utf8_string', alias_ipv6_to_ipv4 => 1, }, ); subtest( 'Tree made from GeoLite2 sample data', sub { my %trees; @trees{ 'pre-thaw', 'post-thaw' } = test_freeze_thaw($tree); my $dir = tempdir( CLEANUP => 1 ); my %readers; for my $key ( keys %trees ) { my $file = "$dir/$key.mmdb"; open my $fh, '>:raw', $file; $trees{$key}->write_tree($fh); close $fh; $readers{$key} = MaxMind::DB::Reader->new( file => $file ); } my %expect = ( '1.64.242.0' => 'HK', '1.72.10.0' => 'JP', '1.72.10.1' => 'JP', '1.72.10.127' => 'JP', '2001:230::abcd:abcd' => 'KR', '2001:67c:50:1928:1234::42ff' => 'NL', ); for my $ip ( sort keys %expect ) { for my $key ( sort keys %readers ) { my $reader = $readers{$key}; is( $reader->record_for_address($ip), $expect{$ip}, "$ip record is $expect{$ip} - $key" ); } } } ); } { my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test tree' }, merge_strategy => 'toplevel', map_key_type_callback => sub { 'uint32' }, # Like the ::/0 insertion case in Tree.t, if we don't turn this off, # then our insert below of ::/1 silently gets ignored, since that would # contain FIXED_EMPTY records. remove_reserved_networks => 0, ); $tree->insert_network( Net::Works::Network->new_from_string( string => '::0/1' ), { value => 42 }, ); subtest( 'Tree with only one network - ::0/1', sub { test_freeze_thaw($tree); test_freeze_thaw_optional_params($tree); } ); } done_testing(); sub _data_record { my $i = shift; return { utf8_string => 'unicode! ☯ - ♫ - ' . $i, double => 42.123456 + $i, bytes => pack( 'N', 42 + $i ), uint16 => 100 + $i, uint32 => 2**28 + $i, int32 => -1 * ( 2**28 + $i ), uint64 => ( uint128(1) << 60 ) + $i, uint128 => ( uint128(1) << 120 ) + $i, array => [ 1, 2, 3, $i ], map => { mapX => { utf8_stringX => 'hello - ' . $i, arrayX => [ 7, 8, 9, $i ], }, }, boolean => $i % 2, float => 1.1 + $i, }; } Tree-insert-range.t100644000000000000 1461113321164704 23256 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writeruse strict; use warnings; use lib 't/lib'; use MaxMind::DB::Writer::Tree (); use Test::More; subtest 'IPv6 test start_ip == end_ip insert' => sub { my $tree = _make_tree(6); my $ip = '2001:4860:4860::8888'; _test_ranges( $tree, [ [ $ip, $ip ] ], {}, [ '2001:4860:4860::8887', '2001:4860:4860::8889' ] ); }; subtest 'IPv6 complicated ranges' => sub { my $tree = _make_tree(6); my $data = { start_ip => '2001:4860:4860::1' }; _test_ranges( $tree, [ [ '2001:4860:4860::1', '2001:4860:4860::FFFE' ] ], { '2001:4860:4860::1' => $data, '2001:4860:4860::2' => $data, '2001:4860:4860::4' => $data, '2001:4860:4860::8' => $data, '2001:4860:4860::10' => $data, '2001:4860:4860::20' => $data, '2001:4860:4860::40' => $data, '2001:4860:4860::80' => $data, '2001:4860:4860::100' => $data, '2001:4860:4860::200' => $data, '2001:4860:4860::400' => $data, '2001:4860:4860::800' => $data, '2001:4860:4860::1000' => $data, '2001:4860:4860::2000' => $data, '2001:4860:4860::4000' => $data, '2001:4860:4860::8000' => $data, }, [ '2001:4860:4860::', '2001:4860:4860::FFFF' ] ); }; subtest 'IPv4 range in IPv6 tree' => sub { my $tree = _make_tree(6); my $data = { start_ip => '1.0.0.1' }; _test_ranges( $tree, [ [ '1.0.0.1', '1.0.0.2' ] ], {}, [ '1.0.0.0', '1.0.0.3' ] ); }; subtest 'IPv4 test start_ip == end_ip insert' => sub { my $tree = _make_tree(4); my $ip = '1.1.1.1'; _test_ranges( $tree, [ [ $ip, $ip ] ], {}, [ '1.1.1.0', '1.1.1.2' ] ); }; subtest 'IPv4 complicated ranges' => sub { my $tree = _make_tree(4); my $data = { start_ip => '1.0.0.1' }; _test_ranges( $tree, [ [ '1.0.0.1', '1.0.0.255' ] ], { '1.0.0.2' => $data, '1.0.0.4' => $data, '1.0.0.8' => $data, '1.0.0.16' => $data, '1.0.0.32' => $data, '1.0.0.64' => $data, '1.0.0.128' => $data, }, [ '1.0.0.0', '1.0.1.0' ] ); }; subtest 'IPv4 overlapping ranges' => sub { my $tree = _make_tree(4); my $data_1 = { start_ip => '1.0.0.1' }; my $data_3 = { start_ip => '1.0.0.3' }; _test_ranges( $tree, [ [ '1.0.0.1', '1.0.0.10' ], [ '1.0.0.3', '1.0.0.4' ] ], { ( map { $_ => $data_1 } ( '1.0.0.1', '1.0.0.2', '1.0.0.5', '1.0.0.6', '1.0.0.7', '1.0.0.8', '1.0.0.9', '1.0.0.10' ) ), ( map { $_ => $data_3 } ( '1.0.0.3', '1.0.0.4' ) ), }, [ '1.0.0.0', '1.0.0.11' ], 0 ); }; { my @empty_ipv4_addresses = qw( 0.0.0.0 0.0.0.255 10.0.0.0 10.0.0.255 100.64.0.0 127.0.0.0 169.254.0.0 172.16.0.0 192.0.0.0 192.0.2.0 192.88.99.0 192.168.0.0 198.18.0.0 198.51.100.0 203.0.113.0 224.0.0.0 240.0.0.0 255.255.255.255 ); subtest 'IPv4 remove reserved networks' => sub { my $tree = _make_tree(4); my $data_0 = { start_ip => '0.0.0.0' }; my $data_128 = { start_ip => '128.0.0.0' }; _test_ranges( $tree, [ [ '0.0.0.0', '127.255.255.255' ], # XXX - We are inserting this as two separate ranges due to # https://github.com/maxmind/MaxMind-DB-Writer-perl/issues/55 [ '128.0.0.0', '255.255.255.255' ], ], { ( map { $_ => $data_0 } ( '1.0.0.0', '126.0.2.255', '11.1.1.11' ) ), ( map { $_ => $data_128 } ( '128.101.101.101', '193.0.0.4', ) ) }, \@empty_ipv4_addresses, 0 ); }; subtest 'IPv6 remove reserved networks' => sub { my $tree = _make_tree(6); my $data_0 = { start_ip => '::' }; _test_ranges( $tree, [ [ '::', 'FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF' ], ], { ( map { $_ => $data_0 } ( '1.0.0.0', '126.0.2.255', '11.1.1.11', '193.0.0.4', '2003::', '8000::', 'a000::', 'efff::' ) ) }, [ @empty_ipv4_addresses, '100::', '2001:1::', '2001:db8::', 'fc00::', 'fe80::', 'ff00::', ], 0, { merge_strategy => 'toplevel' }, ); }; } done_testing(); sub _make_tree { my $ip_version = shift; my %args = @_; return MaxMind::DB::Writer::Tree->new( ip_version => $ip_version, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test tree' }, map_key_type_callback => sub { }, alias_ipv6_to_ipv4 => 1, ); } sub _test_ranges { my $tree = shift; my @insert_ranges = @{ shift() }; my %expected = %{ shift() }; my @unexpected_ips = @{ shift() }; my $test_endpoints = shift // 1; my $insertion_arguments = shift; for my $range (@insert_ranges) { my ( $start_ip, $end_ip ) = @{$range}; my $data = { start_ip => $start_ip }; $tree->insert_range( $start_ip, $end_ip, { start_ip => $start_ip }, $insertion_arguments ); @expected{ $start_ip, $end_ip } = ($data) x 2 if $test_endpoints; } for my $ip ( sort keys %expected ) { is_deeply( $tree->lookup_ip_address($ip), $expected{$ip}, "expected data for $ip" ); } for my $ip (@unexpected_ips) { my $data = $tree->lookup_ip_address($ip); is( $data, undef, "no data for $ip" ) or diag explain $data; } } Tree-ipv6-aliases.t100644000000000000 671113321164704 23145 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writeruse strict; use warnings; use Test::More; use MaxMind::DB::Writer::Tree (); use File::Temp qw( tempdir ); use Net::Works::Address (); use Net::Works::Network (); use Test::Fatal qw( exception ); my $tempdir = tempdir( CLEANUP => 1 ); { my %tests = ( '::1.1.1.1' => { subnet => '::1.1.1.1/128' }, '::1.1.1.2' => { subnet => '::1.1.1.2/127' }, '::255.255.255.2' => { subnet => '::255.255.255.0/120' }, '::fffe:0:0' => { subnet => '::fffe:0:0/96' }, '::fffe:9:a' => { subnet => '::fffe:0:0/96' }, '::ffff:ff02' => { subnet => '::255.255.255.0/120' }, '::1.1.1.3' => { subnet => '::1.1.1.2/127' }, '::ffff:101:101' => { subnet => '::1.1.1.1/128' }, '::ffff:1.1.1.2' => { subnet => '::1.1.1.2/127' }, '::ffff:101:103' => { subnet => '::1.1.1.2/127' }, '::ffff:ffff:ff02' => { subnet => '::255.255.255.0/120' }, '2001:0:101:101::' => { subnet => '::1.1.1.1/128' }, '2001:0:101:102::' => { subnet => '::1.1.1.2/127' }, '2001:0:101:103::' => { subnet => '::1.1.1.2/127' }, '2002:101:101::' => { subnet => '::1.1.1.1/128' }, '2002:101:102::' => { subnet => '::1.1.1.2/127' }, '2002:101:103::' => { subnet => '::1.1.1.2/127' }, '2002:ffff:ff02::' => { subnet => '::255.255.255.0/120' }, '2004::' => { subnet => '2004::/96' }, '2004::9:a' => { subnet => '2004::/96' }, ); my $tree = _write_tree(); for my $address ( sort keys %tests ) { is_deeply( $tree->lookup_ip_address( Net::Works::Address->new_from_string( string => $address, version => 6 ) ), $tests{$address}, "got expected data for $address" ); } # Aliases should never be overwritten. Currently we just throw an # exception is someone tries to overwrite one. In the future, we could do # something smarter, _but_ it isn't clear what the right behavior is. like( exception { $tree->insert_network( '2001::/32', {} ) }, qr/Attempted to overwrite an aliased network./, 'received expected error when trying to overwrite an alias node' ); } done_testing(); sub _write_tree { my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 24, database_type => 'Test', languages => [ 'en', 'zh' ], description => { en => 'Test Database', zh => 'Test Database Chinese', }, alias_ipv6_to_ipv4 => 1, map_key_type_callback => sub { 'utf8_string' }, # Below we try to insert into reserved networks, which fails if we flag # them as fixed empty (255.255.255.0/8 falls under 240.0.0.0/4). remove_reserved_networks => 0, ); # Note: we don't want all of the alias nodes (::ffff:0.0.0.0 and 2002::) # to have adjacent nodes with data, as we want to make sure that the # merging of empty nodes does not merge the alias nodes. my @subnets = map { Net::Works::Network->new_from_string( string => $_, version => 6 ) } qw( ::1.1.1.1/128 ::1.1.1.2/127 ::255.255.255.0/120 ::fffe:0:0/96 2004::/96 ); for my $net (@subnets) { $tree->insert_network( $net, { subnet => $net->as_string() }, ); } return $tree; } Tree-output000755000000000000 013321164704 21650 5ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writerbasic.t100644000000000000 1562313321164704 23305 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writer/Tree-outputuse strict; use warnings; use Test::More; use MaxMind::DB::Common qw( DATA_SECTION_SEPARATOR ); use MaxMind::DB::Metadata; use MaxMind::DB::Writer::Tree; use Net::Works::Network; for my $record_size ( 24, 28, 32 ) { _test_search_tree($record_size); _test_ipv4_networks($record_size); _test_ipv6_networks($record_size); } done_testing(); sub _test_search_tree { my $record_size = shift; my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 4, record_size => $record_size, database_type => 'Test', languages => [ 'en', 'zh' ], description => { en => 'Test Database', zh => 'Test Database Chinese', }, map_key_type_callback => sub { 'utf8_string' }, remove_reserved_networks => 0, ); my @subnets = map { Net::Works::Network->new_from_string( string => $_ ) } qw( 0.0.0.0/2 128.0.0.0/2 ); for my $subnet (@subnets) { $tree->insert_network( $subnet, { ip => $subnet->first()->as_string() } ); } my $node_count = 3; is( $tree->node_count(), $node_count, "tree has $node_count nodes - $record_size-bit record" ); my $buffer; open my $fh, '>:raw', \$buffer or die $!; $tree->write_tree($fh); close $fh or die $!; my $separator = DATA_SECTION_SEPARATOR; my $search_tree_size = $node_count * ( $record_size / 4 ); like( $buffer, qr/^.{$search_tree_size}\Q$separator/, "tree output starts with a search tree of $search_tree_size bytes - $record_size-bit record" ); my $number_encoder = __PACKAGE__->can( q{_} . $record_size . '_bit_number' ); my $one = $number_encoder->(1); my $two = $number_encoder->(2); like( $buffer, qr/\A\Q$one$two/, "first node in search tree points to nodes 1 (L) and 2 (R) - $record_size-bit record" ); my $data_section_size = length($buffer) - $search_tree_size; my %left_record; if ( $record_size == 24 ) { ( $left_record{1}, $left_record{2} ) = map { unpack( N => pack( xa3 => unpack( a3 => $_ ) ) ) } $buffer =~ /^.{6}(.{3}).{3}(.{3})/; } elsif ( $record_size == 28 ) { my @nodes = $buffer =~ /^.{7}(.{7})(.{7})/; for my $num ( 1, 2 ) { my $node = $nodes[ $num - 1 ]; my ( $left_bytes, $middle_bytes, undef ) = unpack( a3Ca3 => $node ); $left_record{$num} = unpack( N => pack( 'Ca*', ( $middle_bytes & 0xf0 ) >> 4, $left_bytes ) ); } } else { ( $left_record{1}, $left_record{2} ) = map { unpack( N => $_ ) } $buffer =~ /^.{8}(.{4}).{4}(.{4})/; } cmp_ok( $left_record{1}, '>', 2, "node 1 left record points to a value outside the search tree - $record_size-bit record" ); cmp_ok( $left_record{1} - $node_count, '<', $data_section_size, "node 1 left record points to a value in the data section - $record_size-bit record" ); cmp_ok( $left_record{2}, '>', 2, "node 2 left record points to a value outside the search tree - $record_size-bit record" ); cmp_ok( $left_record{2} - $node_count, '<', $data_section_size, "node 2 left record points to a value in the data section - $record_size-bit record" ); } ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) sub _24_bit_number { return substr( pack( 'N', $_[0] ), 1, 3 ); } sub _28_bit_number { return pack( N => ( ( $_[0] & 0b11111111_11111111_11111111 ) << 8 ) | ( ( $_[0] >> 20 ) & 0b11110000 ) ); } sub _32_bit_number { return pack( 'N', $_[0] ); } ## use critic sub _test_ipv4_networks { my $record_size = shift; my $desc = "IPv4 - $record_size-bit record"; my $buffer = _write_tree( $record_size, [ Net::Works::Network->range_as_subnets( '1.1.1.1', '1.1.1.32' ) ], { ip_version => 4 }, ); like( $buffer, qr/\0{16}/, 'written-out database includes 16 bytes of 0s' ); my $expect = join q{}, map { chr($_) } ( # map with 1 key 0b11100001, ( # ip 0b01000010, 0b01101001, 0b01110000, ), ( # 1.1.1.1 0b01000111, 0b00110001, 0b00101110, 0b00110001, 0b00101110, 0b00110001, 0b00101110, 0b00110001 ), ); like( $buffer, qr/\Q$expect/, "written-out database includes expected data for one subnet - $desc" ); _test_metadata( $buffer, $desc ); } sub _test_ipv6_networks { my $record_size = shift; my $desc = "IPv6 - $record_size-bit record"; my $buffer = _write_tree( $record_size, [ Net::Works::Network->range_as_subnets( '::1:ffff:ffff', '::2:0000:0059' ) ], { ip_version => 6 }, ); my $expect = join q{}, map { chr($_) } ( # map with 1 key 0b11100001, ( # ip 0b01000010, 0b01101001, 0b01110000, ), ( # ::1:ffff:ffff 0b01001101, 0b00111010, 0b00111010, 0b00110001, 0b00111010, 0b01100110, 0b01100110, 0b01100110, 0b01100110, 0b00111010, 0b01100110, 0b01100110, 0b01100110, 0b01100110 ), ); like( $buffer, qr/\Q$expect/, "written-out database includes expected data for one subnet - $desc" ); _test_metadata( $buffer, $desc ); } sub _write_tree { my $record_size = shift; my $subnets = shift; my $metadata = shift; my $tree = MaxMind::DB::Writer::Tree->new( ip_version => $metadata->{ip_version}, record_size => $record_size, database_type => 'Test', languages => [ 'en', 'zh' ], description => { en => 'Test Database', zh => 'Test Database Chinese', }, map_key_type_callback => sub { 'utf8_string' }, remove_reserved_networks => 0, ); for my $subnet ( @{$subnets} ) { $tree->insert_network( $subnet, { ip => $subnet->first()->as_string() } ); } my $buffer; open my $fh, '>', \$buffer or die $!; $tree->write_tree($fh); close $fh or die $!; return $buffer; } sub _test_metadata { my $buffer = shift; my $desc = shift; like( $buffer, qr/\xab\xcd\xefMaxMind\.com/, "written-out database includes metadata start marker - $desc" ); for my $key ( sort map { $_->name() } MaxMind::DB::Metadata->meta()->get_all_attributes() ) { like( $buffer, qr/\xab\xcd\xefMaxMind\.com.*\Q$key/s, "written-out database includes metadata key $key - $desc" ); } } Tree-freeze-thaw-large-tree.t100644000000000000 711413321164704 23502 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/xt/authoruse strict; use warnings; use utf8; use autodie; use lib 't/lib'; use Test::Requires { JSON => 0, 'MaxMind::DB::Reader' => 0.040000, }; use Test::MaxMind::DB::Writer qw( test_freeze_thaw ); use Test::More; use File::Temp qw( tempdir ); use JSON; use Math::Int128 qw( uint128 ); use MaxMind::DB::Reader; use MaxMind::DB::Writer::Tree; use Net::Works::Network; my $json_file = 't/test-data/GeoLite2-Country.json'; unless ( -f $json_file ) { diag(<<"EOF"); In order to run this test you need to create a JSON dump of a GeoLite2 Country database. You can do this with the mmdb-dump-database script that ships with MaxMind::DB::Reader. Note that this script doesn't generate 100% correct JSON, so you'll need to trim off the trailing comma it leaves in on the last record of the array. Save this JSON file to $json_file We don't include this file in the repo since it ends up being around 650MB in size. EOF plan skip_all => "This test requires the $json_file file"; } my @languages = qw( de en es fr ja pt-BR ru zh-CN ); my %type_map = ( city => 'map', continent => 'map', country => 'map', geoname_id => 'uint32', is_anonymous_proxy => 'boolean', is_satellite_provider => 'boolean', latitude => 'double', location => 'map', longitude => 'double', metro_code => 'uint16', names => 'map', postal => 'map', registered_country => 'map', represented_country => 'map', subdivisions => [ 'array', 'map' ], traits => 'map', ); my $map_key_type_callback = sub { $type_map{ $_[0] } // 'utf8_string' }; my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 32, database_type => 'Test-GeoLite2-Country', languages => \@languages, description => { en => 'Test GeoLite2 Country' }, merge_record_collisions => 1, alias_ipv6_to_ipv4 => 1, map_key_type_callback => $map_key_type_callback, ); open my $fh, '<', $json_file or die $!; my $geolite2_data = do { local $/ = undef; <$fh> }; my $geolite_data = JSON->new->decode($geolite2_data); close $fh or die $!; my $i = 0; for my $geolite_entry ( @{$geolite_data} ) { my ($network) = keys %{$geolite_entry}; $tree->insert_network( Net::Works::Network->new_from_string( string => $network ), $geolite_entry->{$network}, ); $i++; diag("Inserted $i records") unless $i % 100_000; } test_freeze_thaw($tree); my $dir = tempdir( CLEANUP => 1 ); my $frozen_file = "$dir/Test-GeoLite2-Country.frozen"; $tree->freeze_tree($frozen_file); my $mmdb_file = "$dir/Test-GeoLite2-Country.mmdb"; if ( my $pid = fork ) { waitpid $pid, 0 or die $!; } else { my $thawed_tree = MaxMind::DB::Writer::Tree->new_from_frozen_tree( filename => $frozen_file, map_key_type_callback => $map_key_type_callback, ); open $fh, '>', $mmdb_file or die $!; $thawed_tree->write_tree($fh); close $fh or die $!; exit 0; } my $reader = MaxMind::DB::Reader->new( file => $mmdb_file ); for my $i ( 0 .. int( ( scalar @{$geolite_data} ) / 777 ) ) { my $geolite_entry = $geolite_data->[ $i * 777 ]; my ($network) = keys %{$geolite_entry}; my $ip = $network =~ s{/.+$}{}r; is_deeply( $reader->record_for_address($ip), $geolite_entry->{$network}, "record for $ip" ); } done_testing(); Writer000755000000000000 013321164704 21100 5ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/lib/Test/MaxMind/DBIterator.pm100644000000000000 444413321164704 23375 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/lib/Test/MaxMind/DB/Writerpackage Test::MaxMind::DB::Writer::Iterator; use strict; use warnings; use Net::Works::Network (); sub new { my $class = shift; my $ip_version = shift; return bless { ip_version => $ip_version }, $class; } ## no critic (Subroutines::ProhibitManyArgs) sub process_node_record { my $self = shift; my $node_num = shift; my $dir = shift; my $node_ip_num = shift; my $node_prefix_length = shift; $self->_saw_network( $node_ip_num, $node_prefix_length, 'node' ); $self->_saw_record( $node_num, $dir ); push @{ $self->{node_records} }, $self->_nw_network( $node_ip_num, $node_prefix_length ); return; } sub process_empty_record { my $self = shift; my $node_num = shift; my $dir = shift; my $node_ip_num = shift; my $node_prefix_length = shift; $self->_saw_network( $node_ip_num, $node_prefix_length, 'empty' ); $self->_saw_record( $node_num, $dir ); return; } sub process_data_record { my $self = shift; my $node_num = shift; my $dir = shift; my $node_ip_num = shift; my $node_prefix_length = shift; my $record_ip_num = shift; my $record_prefix_length = shift; my $value = shift; $self->_saw_network( $node_ip_num, $node_prefix_length, 'data' ); $self->_saw_record( $node_num, $dir ); push @{ $self->{data_records} }, [ $self->_nw_network( $record_ip_num, $record_prefix_length ), $value, ]; return; } sub _saw_network { my $self = shift; my $ip_num = shift; my $prefix_length = shift; my $network = $self->_nw_network( $ip_num, $prefix_length ); $self->{networks}{ $network->as_string() }++; } sub _saw_record { my $self = shift; my $node_num = shift; my $dir = shift; $self->{records}{"$node_num-$dir"}++; return; } sub _nw_network { my $self = shift; my $ip_num = shift; my $prefix_length = shift; return Net::Works::Network->new_from_integer( integer => $ip_num, prefix_length => $prefix_length, version => $self->{ip_version}, ); } 1; 0-0-0-0.t100644000000000000 262013321164704 22763 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writer/Tree-outputuse strict; use warnings; use Test::More; use Test::Requires ( 'MaxMind::DB::Reader' => 0.040000, ); use MaxMind::DB::Writer::Tree; use File::Temp qw( tempdir ); use MaxMind::DB::Reader; use Net::Works::Network; my $tempdir = tempdir( CLEANUP => 1 ); { my $filename = _write_tree(); my $reader = MaxMind::DB::Reader->new( file => $filename ); for my $address (qw( 0.0.0.0 0.0.0.1 0.0.0.255 )) { is_deeply( $reader->record_for_address($address), { ip => '0.0.0.0', }, "got expected data for $address" ); } } done_testing(); sub _write_tree { my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 4, record_size => 24, database_type => 'Test', languages => [ 'en', 'zh' ], description => { en => 'Test Database', zh => 'Test Database Chinese', }, map_key_type_callback => sub { 'utf8_string' }, remove_reserved_networks => 0 ); my $subnet = Net::Works::Network->new_from_string( string => '0.0.0.0/24', version => 4, ); $tree->insert_network( $subnet, { ip => '0.0.0.0' }, ); my $filename = $tempdir . '/Test-0-network.mmdb'; open my $fh, '>', $filename or die $!; $tree->write_tree($fh); close $fh or die $!; return $filename; } Serializer-types000755000000000000 013321164704 22666 5ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writermap.t100644000000000000 116313321164704 23771 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writer/Serializer-typesuse strict; use warnings; use lib 't/lib'; use Test::Fatal; use Test::MaxMind::DB::Common::Data qw( test_cases_for ); use Test::MaxMind::DB::Writer::Serializer qw( test_encoding_of_type ); use Test::More; use MaxMind::DB::Writer::Serializer; test_encoding_of_type( map => test_cases_for('map') ); { my $serializer = MaxMind::DB::Writer::Serializer->new( map_key_type_callback => sub { } ); like( exception { $serializer->_type_for_key('bad key') }, qr/\QCould not determine the type for map key "bad key"/, 'cannot guess the type for an unknown hash key' ); } done_testing(); Tree-data-references.t100644000000000000 227213321164704 23670 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writeruse strict; use warnings; use Devel::Refcount qw( refcount ); use MaxMind::DB::Writer::Tree; use Net::Works::Network; use Test::More; subtest 'Reference counting when replacing node, no merging' => sub { _test_insert(); }; subtest 'Reference counting with merging' => sub { _test_insert( merge_strategy => 'toplevel' ); }; sub _test_insert { my %extra_tree_args = @_; my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test' }, map_key_type_callback => sub { }, %extra_tree_args, ); my $network = Net::Works::Network->new_from_string( string => '8.23.0.0/16', version => 6 ); my $data = { test => 1 }; $tree->insert_network( $network, $data, ); is( refcount($data), 2, 'ref count of 2 after initial insert' ); $tree->insert_network( $network, { blah => 2 }, ); is( refcount($data), 1, 'ref count of 1 after data is overwritten' ); } done_testing(); Serializer.pm100644000000000000 434713321164704 23717 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/lib/Test/MaxMind/DB/Writerpackage Test::MaxMind::DB::Writer::Serializer; use strict; use warnings; use List::AllUtils qw( all natatime ); use MaxMind::DB::Writer::Serializer; use Scalar::Util qw( blessed ); use Test::Bits; use Test::More; use Exporter qw( import ); our @EXPORT_OK = qw( test_encoding_of_type ); sub test_encoding_of_type { my $type = shift; my $tests = shift; my $iter = natatime 2, @{$tests}; while ( my ( $input, $expect ) = $iter->() ) { my $desc = "packed $type - "; if ( ref $input && !blessed $input ) { $desc .= ref $input eq 'HASH' ? 'hash with ' . ( scalar keys %{$input} ) . ' keys' : 'array with ' . ( scalar @{$input} ) . ' keys'; } else { $desc .= length($input) > 50 ? substr( $input, 0, 50 ) . '...(' . length($input) . ')' : $input; } my $serializer = MaxMind::DB::Writer::Serializer->new( _deduplicate_data => 0, map_key_type_callback => \&_map_key_type, ); $serializer->store_data( $type, $input, ( $type eq 'array' ? 'utf8_string' : () ), ); bits_is( ${ $serializer->buffer() }, $expect, $desc ); } } my %geoip_keys = ( area_code => 'utf8_string', description => 'map', geonames_id => 'uint32', latitude => 'double', location_id => 'uint32', longitude => 'double', metro_code => 'uint16', name => 'map', postal_code => 'utf8_string', ); my %metadata_keys = ( binary_format_major_version => 'uint16', binary_format_minor_version => 'uint16', build_epoch => 'uint64', database_type => 'utf8_string', description => 'map', ip_version => 'uint16', languages => [ 'array', 'utf8_string' ], node_count => 'uint32', record_size => 'uint32', ); sub _map_key_type { my $key = shift; # locale id return 'utf8_string' if $key =~ /^[a-z]{2,3}(?:-[A-Z]{2})?$/; return $geoip_keys{$key} || $metadata_keys{$key}; } 1; utf8-data.t100644000000000000 356413321164704 24002 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writer/Tree-outputuse strict; use warnings; use Test::Builder; use Test::More; use Test::Requires ( 'MaxMind::DB::Reader' => 0.040000, ); use MaxMind::DB::Writer::Tree; use Encode (); use File::Temp qw( tempdir ); use MaxMind::DB::Reader; use Net::Works::Network; { my $tb = Test::Builder->new(); for ( $tb->output, $tb->failure_output, $tb->todo_output ) { binmode $_, ':encoding(UTF-8)' or die $!; } } my $tempdir = tempdir( CLEANUP => 1 ); my $utf8_string = "\x{4eba}"; { my $filename = _write_tree(); my $reader = MaxMind::DB::Reader->new( file => $filename ); for my $address (qw( 1.2.3.0 1.2.3.128 1.2.3.255 )) { is_deeply( $reader->record_for_address($address), { subnet => '1.2.3.0/24', string => $utf8_string, }, "got expected data for $address" ); } my $string = $reader->record_for_address('1.2.3.0')->{string}; ok( Encode::is_utf8($string), "string from lookup ($string) is marked as utf8" ); } done_testing(); sub _write_tree { my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 4, record_size => 24, database_type => 'Test', languages => [ 'en', 'zh' ], description => { en => 'Test Database', zh => 'Test Database Chinese', }, map_key_type_callback => sub { 'utf8_string' }, ); my $subnet = Net::Works::Network->new_from_string( string => '1.2.3.0/24', version => 4, ); $tree->insert_network( $subnet, { subnet => $subnet->as_string(), string => $utf8_string, }, ); my $filename = $tempdir . '/Test-utf8-string.mmdb'; open my $fh, '>', $filename or die $!; $tree->write_tree($fh); close $fh or die $!; return $filename; } array.t100644000000000000 50213321164704 24306 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writer/Serializer-typesuse strict; use warnings; use lib 't/lib'; use Test::Fatal; use Test::MaxMind::DB::Common::Data qw( test_cases_for ); use Test::MaxMind::DB::Writer::Serializer qw( test_encoding_of_type ); use Test::More; use MaxMind::DB::Writer::Serializer; test_encoding_of_type( array => test_cases_for('array') ); done_testing(); bytes.t100644000000000000 43413321164704 24322 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writer/Serializer-typesuse strict; use warnings; use lib 't/lib'; use Test::Fatal; use Test::MaxMind::DB::Common::Data qw( test_cases_for ); use Test::MaxMind::DB::Writer::Serializer qw( test_encoding_of_type ); use Test::More; test_encoding_of_type( bytes => test_cases_for('bytes') ); done_testing(); float.t100644000000000000 43413321164704 24301 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writer/Serializer-typesuse strict; use warnings; use lib 't/lib'; use Test::Fatal; use Test::MaxMind::DB::Common::Data qw( test_cases_for ); use Test::MaxMind::DB::Writer::Serializer qw( test_encoding_of_type ); use Test::More; test_encoding_of_type( float => test_cases_for('float') ); done_testing(); int32.t100644000000000000 43413321164704 24133 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writer/Serializer-typesuse strict; use warnings; use lib 't/lib'; use Test::Fatal; use Test::MaxMind::DB::Common::Data qw( test_cases_for ); use Test::MaxMind::DB::Writer::Serializer qw( test_encoding_of_type ); use Test::More; test_encoding_of_type( int32 => test_cases_for('int32') ); done_testing(); Tree-record-collisions.t100644000000000000 7436013321164704 24321 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writeruse strict; use warnings; use lib 't/lib'; use Test::Fatal qw( exception ); use Test::MaxMind::DB::Writer qw( test_tree test_freeze_thaw ); use Test::More; use Test::Warnings qw( :all ); use MaxMind::DB::Writer::Tree (); use Net::Works::Network (); subtest 'simple IPv6 merge' => sub { my %asn = ( autonomous_system_number => 21928, autonomous_system_organization => 'T-Mobile USA, Inc.', ); my $isp = 'T-Mobile ISP'; my $org = 'T-Mobile Org'; my @pairs = ( [ Net::Works::Network->new_from_string( string => '::172.56.0.0/112' ) => \%asn, ], [ Net::Works::Network->new_from_string( string => '::172.56.0.0/112' ) => { isp => $isp }, ], [ Net::Works::Network->new_from_string( string => '::172.32.0.0/107' ) => { organization => $org }, ], ); my @expect = ( [ Net::Works::Network->new_from_string( string => '::172.56.9.251/128' ) => { %asn, isp => $isp, organization => $org, } ], ); my @warnings = warnings { test_tree( \@pairs, \@expect, 'data hashes for records are merged on collision - ipv6', { merge_record_collisions => 1 }, ) }; is( scalar @warnings, 2, 'received two warnings' ) or diag explain @warnings; like( $warnings[0], qr/merge_record_collisions is deprecated./, 'merge_record_collisions deprecation message' ); }; subtest 'merge - small net, large net, small net' => sub { my @pairs = ( [ Net::Works::Network->new_from_string( string => '5.0.0.0/32' ) => { first_in => 1 }, ], [ Net::Works::Network->new_from_string( string => '5.0.0.0/30' ) => { second_in => 2 }, ], [ Net::Works::Network->new_from_string( string => '5.0.0.0/32' ) => { third_in => 3 }, ], ); my @expect = ( [ Net::Works::Network->new_from_string( string => '5.0.0.0/32' ) => { first_in => 1, second_in => 2, third_in => 3, } ], ( map { [ $_ => { second_in => 2 } ] } Net::Works::Network->range_as_subnets( '5.0.0.1' => '5.0.0.3' ) ), ); test_tree( \@pairs, \@expect, 'data hashes for records are merged on collision - small net, large net, small net', { merge_strategy => 'toplevel' }, ); }; subtest 'merge - large net, small net, large net' => sub { my @pairs = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/30' ) => { first_in => 1 }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.0/32' ) => { second_in => 2 }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.0/30' ) => { third_in => 3 }, ], ); my @expect = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/32' ) => { first_in => 1, second_in => 2, third_in => 3, } ], [ Net::Works::Network->new_from_string( string => '2.0.0.1/32' ) => { first_in => 1, third_in => 3, } ], ); test_tree( \@pairs, \@expect, 'data hashes for records are merged on collision - large net, small net, large net', { merge_strategy => 'toplevel' }, ); }; subtest 'merge - same network' => sub { my @pairs = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/32' ) => { first_in => 1 }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.0/32' ) => { second_in => 2 }, ], ); my @expect = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/32' ) => { first_in => 1, second_in => 2, } ], ); test_tree( \@pairs, \@expect, 'data hashes for records are merged on collision - same network', { merge_strategy => 'toplevel' }, ); }; subtest 'merge - overlapping network, larger net first' => sub { my @pairs = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/23' ) => { first_in => 1 }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.0/24' ) => { second_in => 2 }, ], ); my @expect = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/32' ) => { first_in => 1, second_in => 2, } ], [ Net::Works::Network->new_from_string( string => '2.0.1.0/32' ) => { first_in => 1, } ], ); test_tree( \@pairs, \@expect, 'data hashes for records are merged on collision - overlapping network, larger net first', { merge_strategy => 'toplevel' }, ); }; subtest 'merge - overlapping network, smaller net first' => sub { my @pairs = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/24' ) => { first_in => 1 }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.0/23' ) => { second_in => 2 }, ], ); my @expect = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/32' ) => { first_in => 1, second_in => 2, } ], [ Net::Works::Network->new_from_string( string => '2.0.1.0/32' ) => { second_in => 2, } ], ); test_tree( \@pairs, \@expect, 'data hashes for records are merged on collision - overlapping network, smaller net first', { merge_strategy => 'toplevel' }, ); }; subtest 'merge - smaller nets first' => sub { my @pairs = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/32' ) => { first_in => 1 }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.0/31' ) => { second_in => 2 }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.0/30' ) => { third_in => 3 }, ], ); my @expect = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/32' ) => { first_in => 1, second_in => 2, third_in => 3, } ], [ Net::Works::Network->new_from_string( string => '2.0.0.1/32' ) => { second_in => 2, third_in => 3, } ], [ Net::Works::Network->new_from_string( string => '2.0.0.2/31' ) => { third_in => 3, } ], ); test_tree( \@pairs, \@expect, 'data hashes for records are merged on collision - smaller nets first', { merge_strategy => 'toplevel' }, ); }; subtest 'merge - smaller net first' => sub { my @pairs = ( [ Net::Works::Network->new_from_string( string => '1.0.0.0/24' ) => { first_in => 1 }, ], ( map { [ $_ => { second_in => 2 } ] } Net::Works::Network->range_as_subnets( '1.0.0.1' => '1.0.0.2' ) ), [ Net::Works::Network->new_from_string( string => '1.0.0.0/24' ) => { third_in => 3 }, ], [ Net::Works::Network->new_from_string( string => '1.0.0.0/16' ) => { fourth_in => 4 }, ], [ Net::Works::Network->new_from_string( string => '1.0.0.0/16' ) => { fifth_in => 5 }, ], ); my @expect = ( [ Net::Works::Network->new_from_string( string => '1.0.0.0/32' ) => { first_in => 1, third_in => 3, fourth_in => 4, fifth_in => 5, } ], ( map { [ $_ => { first_in => 1, second_in => 2, third_in => 3, fourth_in => 4, fifth_in => 5, } ] } Net::Works::Network->range_as_subnets( '1.0.0.1' => '1.0.0.2' ) ), ( map { [ $_ => { first_in => 1, third_in => 3, fourth_in => 4, fifth_in => 5, } ] } Net::Works::Network->range_as_subnets( '1.0.0.3' => '1.0.0.4' ) ), ( map { [ $_ => { fourth_in => 4, fifth_in => 5, } ] } Net::Works::Network->range_as_subnets( '1.0.255.254' => '1.0.255.255' ) ), ); test_tree( \@pairs, \@expect, 'data hashes for records are merged on collision - smaller net first', { merge_strategy => 'toplevel' }, ); }; subtest 'merge - larger net first' => sub { my @pairs = ( [ Net::Works::Network->new_from_string( string => '1.0.0.0/24' ) => { foo => 42 }, ], ( map { [ $_ => { bar => 84 } ] } Net::Works::Network->range_as_subnets( '1.0.0.1' => '1.0.0.15' ) ), ); my @expect = ( [ Net::Works::Network->new_from_string( string => '1.0.0.0/32' ) => { foo => 42 } ], ( map { [ $_ => { foo => 42, bar => 84 } ] } Net::Works::Network->range_as_subnets( '1.0.0.1' => '1.0.0.15' ) ), ( map { [ $_ => { foo => 42 } ] } Net::Works::Network->range_as_subnets( '1.0.0.16' => '1.0.0.255' ) ), ); test_tree( \@pairs, \@expect, 'data hashes for records are merged on collision - larger net first', { merge_strategy => 'toplevel' }, ); }; subtest 'merge - larger net first' => sub { my @pairs = ( [ Net::Works::Network->new_from_string( string => '1.0.0.0/24' ) => { foo => 42 }, ], ( map { [ $_ => { bar => 84 } ] } Net::Works::Network->range_as_subnets( '1.0.0.1' => '1.0.0.15' ) ), ( map { [ $_ => { baz => 168 } ] } Net::Works::Network->range_as_subnets( '1.0.0.9' => '1.0.0.13' ) ), ); my @expect = ( [ Net::Works::Network->new_from_string( string => '1.0.0.0/32' ) => { foo => 42 } ], ( map { [ $_ => { foo => 42, bar => 84 } ] } Net::Works::Network->range_as_subnets( '1.0.0.1' => '1.0.0.8' ) ), ( map { [ $_ => { foo => 42, bar => 84, baz => 168 } ] } Net::Works::Network->range_as_subnets( '1.0.0.9' => '1.0.0.13' ) ), ( map { [ $_ => { foo => 42, bar => 84 } ] } Net::Works::Network->range_as_subnets( '1.0.0.14' => '1.0.0.15' ) ), ( map { [ $_ => { foo => 42 } ] } Net::Works::Network->range_as_subnets( '1.0.0.16' => '1.0.0.255' ) ), ); test_tree( \@pairs, \@expect, 'data hashes for records are merged on repeated collision - larger net first', { merge_strategy => 'toplevel' }, ); }; subtest 'last in value wins when overwriting' => sub { my @pairs = ( [ Net::Works::Network->new_from_string( string => '1.0.0.0/32' ) => { first_in => 1 }, ], [ Net::Works::Network->new_from_string( string => '1.0.0.0/31' ) => { first_in => 2, second_in => 2, }, ], [ Net::Works::Network->new_from_string( string => '1.0.0.0/32' ) => { first_in => 3, second_in => 3, third_in => 3, }, ], ); my @expect = ( [ Net::Works::Network->new_from_string( string => '1.0.0.0/32' ) => { first_in => 3, second_in => 3, third_in => 3, } ], [ Net::Works::Network->new_from_string( string => '1.0.0.1/32' ) => { first_in => 2, second_in => 2, } ], ); test_tree( \@pairs, \@expect, 'last in value wins when overwriting', { merge_strategy => 'toplevel' }, ); }; subtest 'force_overwrite with merge_record_collisions' => sub { my @pairs = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/30' ) => { first_in => 1 }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.2/31' ) => { second_in => 2 }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.2/32' ) => {}, { force_overwrite => 1 }, ], ); my @expect = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/31' ) => { first_in => 1, } ], [ Net::Works::Network->new_from_string( string => '2.0.0.2/32' ) => {} ], [ Net::Works::Network->new_from_string( string => '2.0.0.3/32' ) => { first_in => 1, second_in => 2, } ], ); my @warnings = warnings { test_tree( \@pairs, \@expect, 'force_overwrite overwrites record even when merge_record_collisions is enabled', { merge_strategy => 'toplevel' }, ) }; is( scalar @warnings, 2, 'received 2 warnings' ); like( $warnings[0], qr/force_overwrite is deprecated/, 'received deprecation warning' ); }; subtest 'merge subrecord only if parent exists - hashes' => sub { my @pairs = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/32' ) => { parent => { sibling => { child => 1 } } }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.1/32' ) => { non_parent => { non_subling => 1 } }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.0/30' ) => { parent => { sibling => { child => 2 }, self => 0 } }, { insert_only_if_parent_exists => 1 }, ], ); my @expect = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/32' ) => { parent => { sibling => { child => 2 }, self => 0 } }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.1/32' ) => { non_parent => { non_subling => 1 } }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.2/31' ) => undef, ], ); my @warnings = warnings { test_tree( \@pairs, \@expect, 'merge hashes insert_only_if_parent_exists inserts correctly', { merge_strategy => 'recurse' }, ) }; is( scalar @warnings, 2, 'received two warnings' ); like( $warnings[0], qr/The argument insert_only_if_parent_exists is deprecated./, 'expected deprecation message' ); }; subtest 'merge subrecord only if parent exists - arrays' => sub { my @pairs = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/32' ) => { grandparent => [ { sibling => 1 } ], scalars => [ 1, 2 ], already => { exists => 2 }, }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.1/32' ) => { grandparent => [], scalars => [], } ], [ Net::Works::Network->new_from_string( string => '2.0.0.0/31' ) => { grandparent => [ { self => 0 } ], scalars => [3], new_array => [ { new => 0 } ], already => { exists => 1 }, }, { merge_strategy => 'add-only-if-parent-exists' }, ], ); my @expect = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/32' ) => { grandparent => [ { sibling => 1, self => 0 } ], scalars => [ 3, 2 ], already => { exists => 1 }, }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.1/32' ) => { grandparent => [], scalars => [3], }, ], ); test_tree( \@pairs, \@expect, 'merge arrays insert_only_if_parent_exists inserts correctly', { merge_strategy => 'recurse' }, ); }; subtest 'merge subrecord only if parent exists - overwriting' => sub { my @pairs = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/24' ) => { location => {} }, ], [ Net::Works::Network->new_from_string( string => '::/0' ) => { location => { accuracy_radius => 1000 } }, { merge_strategy => 'add-only-if-parent-exists' }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.0/30' ) => { location => { accuracy_radius => 10 } }, { merge_strategy => 'add-only-if-parent-exists' }, ], ); my @expect = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/30' ) => { location => { accuracy_radius => 10 } }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.255/32' ) => { location => { accuracy_radius => 1000 } }, ], ); test_tree( \@pairs, \@expect, 'insert_only_if_parent_exists overwrites correctly', { ip_version => 6 }, 1 ); }; subtest 'merge strategies' => sub { my @pairs = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/30' ) => { families => [ { husband => 'Fred', wife => 'Pearl', }, ], year => 1960, }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.2/32' ) => { families => [ { wife => 'Wilma', child => 'Pebbles', }, { husband => 'Barney', wife => 'Betty', child => 'Bamm-Bamm', }, ], company => 'Hanna-Barbera Productions', } ], ); my @expect_recurse = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/31' ) => { families => [ { husband => 'Fred', wife => 'Pearl', }, ], year => 1960, }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.2/32' ) => { families => [ { husband => 'Fred', wife => 'Wilma', # note replaced value child => 'Pebbles', }, { husband => 'Barney', wife => 'Betty', child => 'Bamm-Bamm', }, ], year => 1960, company => 'Hanna-Barbera Productions', }, ], ); test_tree( \@pairs, \@expect_recurse, 'recurse merge strategy', { merge_strategy => 'recurse' }, ); my @expect_toplevel = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/31' ) => { families => [ { husband => 'Fred', wife => 'Pearl', }, ], year => 1960, }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.2/32' ) => { families => [ { wife => 'Wilma', child => 'Pebbles', }, { husband => 'Barney', wife => 'Betty', child => 'Bamm-Bamm', }, ], year => 1960, company => 'Hanna-Barbera Productions', }, ], ); test_tree( \@pairs, \@expect_toplevel, 'expect_toplevel merge strategy', { merge_strategy => 'toplevel' }, ); }; subtest 'insert-specific merge strategies' => sub { my @pairs = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/30' ) => { parent => { sibling => { child => 1 } }, aunt => { cousin => 1 }, }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.0/32' ) => { new => 1 }, { merge_strategy => 'none' } ], [ Net::Works::Network->new_from_string( string => '2.0.0.1/32' ) => { parent => { new => 1 } }, { merge_strategy => 'recurse' } ], [ Net::Works::Network->new_from_string( string => '2.0.0.2/32' ) => { aunt => { step_cousin => 1 } }, { merge_strategy => 'toplevel' } ], [ Net::Works::Network->new_from_string( string => '2.0.0.3/32' ) => { aunt => { step_cousin => 1 }, uncle => { cousin => 2 } }, { merge_strategy => 'add-only-if-parent-exists' } ], ); my @expect = ( [ Net::Works::Network->new_from_string( string => '2.0.0.0/32' ) => { new => 1 }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.1/32' ) => { parent => { sibling => { child => 1 }, new => 1 }, aunt => { cousin => 1 }, }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.2/32' ) => { parent => { sibling => { child => 1 } }, aunt => { step_cousin => 1 }, }, ], [ Net::Works::Network->new_from_string( string => '2.0.0.3/32' ) => { parent => { sibling => { child => 1 } }, aunt => { cousin => 1, step_cousin => 1 }, }, ], ); test_tree( \@pairs, \@expect, 'insert-specific merge strategies', ); }; subtest 'merge error on hash mismatch' => sub { my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 4, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test tree' }, merge_strategy => 'toplevel', map_key_type_callback => sub { }, ); $tree->insert_network( Net::Works::Network->new_from_string( string => '1.0.0.0/24' ), { hash => 1 }, ); for my $data ( 'foo', 42, [ array => 1 ] ) { like( exception { $tree->insert_network( Net::Works::Network->new_from_string( string => '1.0.0.0/28' ), $data, ); }, qr{\QCannot merge data records unless both records are hashes - inserting 1.0.0.0/28}, "cannot merge records on collision when the data is not a hash - data = $data" ); } }; subtest 'merge error on hash-array mismatch' => sub { my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 4, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test tree' }, merge_strategy => 'toplevel', map_key_type_callback => sub { }, ); $tree->insert_network( Net::Works::Network->new_from_string( string => '1.0.0.0/24' ), [ array => 1 ], ); like( exception { $tree->insert_network( Net::Works::Network->new_from_string( string => '1.0.0.0/28' ), { hash => 1 }, ); }, qr{\QCannot merge data records unless both records are hashes - inserting 1.0.0.0/28}, 'cannot merge records on collision when the data is not a hash - larger record data is an array' ); }; subtest 'Test merging into aliased nodes' => sub { my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test tree' }, merge_strategy => 'toplevel', map_key_type_callback => sub { 'utf8_string' }, alias_ipv6_to_ipv4 => 1, ); _insert_network( $tree, $_ ) for qw( 1.0.0.0/24 ::/1 2001::/31 ); my @networks = qw( ::ffff:1.0.0.0/104 2002:0101:0101:0101::/64 ); for my $network (@networks) { like( exception { _insert_network( $tree, $network ) }, qr/Attempted to insert into an aliased network/, "Exception when inserting into aliased network $network", ); } my @aliased_networks = qw( 2001::/32 2002::/16 ::ffff:0:0/96 ); for my $network (@aliased_networks) { like( exception { _insert_network( $tree, $network ) }, qr/Attempted to overwrite an aliased network./, "Exception when trying to overwrite alias at $network" ); } test_freeze_thaw($tree); }; subtest 'Test merging away IPv4 root' => sub { my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test tree' }, merge_strategy => 'toplevel', map_key_type_callback => sub { 'utf8_string' }, alias_ipv6_to_ipv4 => 1, ); $tree->insert_network( $_, { data => 1 } ) for qw( 1.0.0.0/24 ::/1 ); test_freeze_thaw($tree); }; subtest 'Test overwriting IPv4 root' => sub { my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test tree' }, merge_strategy => 'toplevel', map_key_type_callback => sub { 'utf8_string' }, alias_ipv6_to_ipv4 => 1, ); _insert_network( $tree, $_ ) for qw( 1.0.0.0/24 0.0.0.0/0 ::/95 ); my @pairs = ( [ Net::Works::Network->new_from_string( string => '1.0.0.0/24' ) => { insert => 1 }, ], [ Net::Works::Network->new_from_string( string => '0.0.0.0/0' ) => { insert => 2 }, ], [ Net::Works::Network->new_from_string( string => '::/95' ) => { insert => 3 }, ], ); my @expect = ( [ Net::Works::Network->new_from_string( string => '1.0.0.0/32' ) => { insert => 3 }, ], [ Net::Works::Network->new_from_string( string => '130.0.0.0/32' ) => { insert => 3 }, ], [ Net::Works::Network->new_from_string( string => '::1:ffff:ffff/128' ) => { insert => 3 }, ], ); test_tree( \@pairs, \@expect, 'IPv4 node is not merged away', { ip_version => 6 }, 1, ); }; sub _insert_network { my $tree = shift; my $network = shift; $tree->insert_network( $network, { value => $network, $network => 1, }, ); } done_testing(); double.t100644000000000000 43613321164704 24450 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writer/Serializer-typesuse strict; use warnings; use lib 't/lib'; use Test::Fatal; use Test::MaxMind::DB::Common::Data qw( test_cases_for ); use Test::MaxMind::DB::Writer::Serializer qw( test_encoding_of_type ); use Test::More; test_encoding_of_type( double => test_cases_for('double') ); done_testing(); uint16.t100644000000000000 41513321164704 24321 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writer/Serializer-typesuse strict; use warnings; use lib 't/lib'; use Test::MaxMind::DB::Common::Data qw( test_cases_for ); use Test::MaxMind::DB::Writer::Serializer qw( test_encoding_of_type ); use Test::More; test_encoding_of_type( uint16 => test_cases_for('uint16') ); done_testing(); uint32.t100644000000000000 245013321164704 24340 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writer/Serializer-typesuse strict; use warnings; use lib 't/lib'; use Test::Fatal; use Test::MaxMind::DB::Common::Data qw( test_cases_for ); use Test::MaxMind::DB::Writer::Serializer qw( test_encoding_of_type ); use Test::More; use MaxMind::DB::Writer::Serializer; test_encoding_of_type( uint32 => test_cases_for('uint32') ); { my $serializer = MaxMind::DB::Writer::Serializer->new( map_key_type_callback => sub { } ); like( exception { $serializer->_encode_uint32(undef) }, qr/\QYou cannot encode undef as an unsigned 32-bit integer./, q{cannot encode undef as an unsigned integer} ); like( exception { $serializer->_encode_uint32('foo') }, qr/\QYou cannot encode foo as an unsigned 32-bit integer. It is not an unsigned integer number/, q{cannot encode "foo" as an unsigned integer} ); like( exception { $serializer->_encode_uint32(-1) }, qr/\QYou cannot encode -1 as an unsigned 32-bit integer. It is not an unsigned integer number./, 'cannot encode -1 as an unsigned integer' ); like( exception { $serializer->_encode_uint32( 2**33 ) }, qr/\QYou cannot encode \E\d+\Q as an unsigned 32-bit integer. It is too big./, 'cannot encode 2**33 as an unsigned 32-bit integer' ); } done_testing(); uint64.t100644000000000000 257513321164704 24355 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writer/Serializer-typesuse strict; use warnings; use lib 't/lib'; use Test::Fatal; use Test::MaxMind::DB::Common::Data qw( test_cases_for ); use Test::MaxMind::DB::Writer::Serializer qw( test_encoding_of_type ); use Test::More; use Math::Int128 qw( uint128 ); use MaxMind::DB::Writer::Serializer; test_encoding_of_type( uint64 => test_cases_for('uint64') ); { my $serializer = MaxMind::DB::Writer::Serializer->new( map_key_type_callback => sub { } ); like( exception { $serializer->_encode_uint64(undef) }, qr/\QYou cannot encode undef as an unsigned 64-bit integer./, q{cannot encode undef as an unsigned integer} ); like( exception { $serializer->_encode_uint64('foo') }, qr/\QYou cannot encode foo as an unsigned 64-bit integer. It is not an unsigned integer number./, q{cannot encode "foo" as an unsigned integer} ); like( exception { $serializer->_encode_uint64(-1) }, qr/\QYou cannot encode -1 as an unsigned 64-bit integer. It is not an unsigned integer number./, 'cannot encode -1 as an unsigned integer' ); like( exception { $serializer->_encode_uint64( uint128('36893488147419103232') ); }, qr/\QYou cannot encode \E[\dA-F]+\Q as an unsigned 64-bit integer. It is too big./, 'cannot encode 2**65 as an unsigned 64 bit integer' ); } done_testing(); Serializer-deduplication.t100644000000000000 455113321164704 24700 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writeruse strict; use warnings; use Test::Bits; use Test::More; use MaxMind::DB::Writer::Serializer; my $serializer = MaxMind::DB::Writer::Serializer->new( map_key_type_callback => sub { 'utf8_string' } ); $serializer->store_data( map => { long_key => 'long_value1' } ); $serializer->store_data( map => { long_key => 'long_value2' } ); $serializer->store_data( map => { long_key2 => 'long_value1' } ); $serializer->store_data( map => { long_key2 => 'long_value2' } ); $serializer->store_data( map => { long_key => 'long_value1' } ); $serializer->store_data( map => { long_key2 => 'long_value2' } ); bits_is( ${ $serializer->buffer() }, [ # map - 1 0b11100001, ( # long_key - 9 0b01001000, 0b01101100, 0b01101111, 0b01101110, 0b01100111, 0b01011111, 0b01101011, 0b01100101, 0b01111001, ), ( # long_value1 - 12 0b01001011, 0b01101100, 0b01101111, 0b01101110, 0b01100111, 0b01011111, 0b01110110, 0b01100001, 0b01101100, 0b01110101, 0b01100101, 0b00110001 ), # map - 1 0b11100001, ( # pointer to long_key - 2 0b00100000, 0b00000001, ), ( # long_value2 - 12 0b01001011, 0b01101100, 0b01101111, 0b01101110, 0b01100111, 0b01011111, 0b01110110, 0b01100001, 0b01101100, 0b01110101, 0b01100101, 0b00110010 ), # map - 1 0b11100001, ( # long_key2 - 10 0b01001001, 0b01101100, 0b01101111, 0b01101110, 0b01100111, 0b01011111, 0b01101011, 0b01100101, 0b01111001, 0b00110010 ), ( # pointer to long_value1 - 2 0b00100000, 0b00001010, ), # map - 1 0b11100001, ( # pointer to long_key2 0b00100000, 0b00100110, ), ( # pointer to long_value2 0b00100000, 0b00011001, ), ( # pointer to first map 0b00100000, 0b00000000, ), ( # pointer to fourth map 0b00100000, 0b00110010, ), ], 'keys, values, and whole maps are all deduplicated' ); done_testing(); Serializer-large-pointer.t100644000000000000 344613321164704 24626 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writeruse strict; use warnings; use Test::Bits; use Test::More; use MaxMind::DB::Reader::Decoder; use MaxMind::DB::Writer::Serializer; my $serializer = MaxMind::DB::Writer::Serializer->new( map_key_type_callback => sub { 'utf8_string' } ); my $first_short_string = 'a short string'; $serializer->store_data( utf8_string => $first_short_string ); my $four_byte_pointer_threshold = 134744064; my $long_string = 'a' x 2**16; while ( length ${ $serializer->buffer() } < $four_byte_pointer_threshold ) { $serializer->store_data( utf8_string => $long_string++ ); } $MaxMind::DB::Writer::Serializer::DEBUG = 1; my $small_pointer = $serializer->store_data( utf8_string => $first_short_string ); my $last_short_string = 'another short string'; $serializer->store_data( utf8_string => $last_short_string ); my $large_pointer = $serializer->store_data( utf8_string => $last_short_string ); my $buffer = $serializer->buffer(); ## no critic (InputOutput::RequireBriefOpen) open my $fh, '<:raw', $buffer or die $!; my $decoder = MaxMind::DB::Reader::Decoder->new( data_source => $fh, ## no critic (Modules::RequireExplicitInclusion, Subroutines::ProhibitCallsToUnexportedSubs) _data_source_size => bytes::length( ${$buffer} ), ); { is( scalar $decoder->decode(0), $first_short_string, 'decoded short string at beginning of encoded data' ); is( scalar $decoder->decode( ( length $first_short_string ) + 1 ), ( 'a' x 2**16 ), 'decoded first long string after short string' ); is( scalar $decoder->decode($small_pointer), $first_short_string, 'decoded small pointer' ); is( scalar $decoder->decode($large_pointer), $last_short_string, 'decoded large pointer' ); } done_testing(); boolean.t100644000000000000 44013321164704 24610 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writer/Serializer-typesuse strict; use warnings; use lib 't/lib'; use Test::Fatal; use Test::MaxMind::DB::Common::Data qw( test_cases_for ); use Test::MaxMind::DB::Writer::Serializer qw( test_encoding_of_type ); use Test::More; test_encoding_of_type( boolean => test_cases_for('boolean') ); done_testing(); pointer.t100644000000000000 245613321164704 24702 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writer/Serializer-typesuse strict; use warnings; use lib 't/lib'; use Test::Fatal; use Test::MaxMind::DB::Common::Data qw( test_cases_for ); use Test::MaxMind::DB::Writer::Serializer qw( test_encoding_of_type ); use Test::More; use MaxMind::DB::Writer::Serializer; test_encoding_of_type( pointer => test_cases_for('pointer') ); { my $serializer = MaxMind::DB::Writer::Serializer->new( map_key_type_callback => sub { } ); like( exception { $serializer->_encode_pointer(undef) }, qr/\QYou cannot encode undef as an unsigned 32-bit integer./, q{cannot encode undef as an unsigned integer} ); like( exception { $serializer->_encode_pointer('foo') }, qr/\QYou cannot encode foo as an unsigned 32-bit integer. It is not an unsigned integer number/, q{cannot encode "foo" as an unsigned integer} ); like( exception { $serializer->_encode_pointer(-1) }, qr/\QYou cannot encode -1 as an unsigned 32-bit integer. It is not an unsigned integer number./, 'cannot encode -1 as an unsigned integer' ); like( exception { $serializer->_encode_pointer( 2**33 ) }, qr/\QYou cannot encode \E\d+\Q as an unsigned 32-bit integer. It is too big./, 'cannot encode 2**33 as an unsigned 32-bit integer' ); } done_testing(); uint128.t100644000000000000 41713321164704 24407 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writer/Serializer-typesuse strict; use warnings; use lib 't/lib'; use Test::MaxMind::DB::Common::Data qw( test_cases_for ); use Test::MaxMind::DB::Writer::Serializer qw( test_encoding_of_type ); use Test::More; test_encoding_of_type( uint128 => test_cases_for('uint128') ); done_testing(); Serializer-utf8-as-bytes.t100644000000000000 140013321164704 24455 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writeruse strict; use warnings; use utf8; use Test::Builder; use Test::Fatal; use Test::More; use Encode (); use MaxMind::DB::Reader::Decoder; use MaxMind::DB::Writer::Serializer; { my $tb = Test::Builder->new(); for ( $tb->output, $tb->failure_output, $tb->todo_output ) { binmode $_, ':encoding(UTF-8)' or die $!; } } my $input = "\x{4eba}"; ok( Encode::is_utf8($input), 'input is marked as utf8 in Perl' ); my $serializer = MaxMind::DB::Writer::Serializer->new( map_key_type_callback => sub { } ); like( exception { $serializer->store_data( bytes => $input ) }, qr/\QYou attempted to store a characters string (人) as bytes/, 'got an error when trying to serialize a character string as bytes' ); done_testing(); ipv6-aliases.t100644000000000000 627613321164704 24513 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writer/Tree-outputuse strict; use warnings; use Test::More; use Test::Requires ( 'MaxMind::DB::Reader' => 0.040000, ); use MaxMind::DB::Writer::Tree; use File::Temp qw( tempdir ); use MaxMind::DB::Reader; use Net::Works::Network; my $tempdir = tempdir( CLEANUP => 1 ); { my $filename = _write_tree(); my $reader = MaxMind::DB::Reader->new( file => $filename ); my %tests = ( '1.1.1.1' => { subnet => '::1.1.1.1/128' }, '::1.1.1.1' => { subnet => '::1.1.1.1/128' }, '1.1.1.2' => { subnet => '::1.1.1.2/127' }, '::1.1.1.2' => { subnet => '::1.1.1.2/127' }, '1.1.1.3' => { subnet => '::1.1.1.2/127' }, '223.255.255.2' => { subnet => '::223.255.255.0/120' }, '::fffe:0:0' => { subnet => '::fffe:0:0/96' }, '::fffe:9:a' => { subnet => '::fffe:0:0/96' }, '::dfff:ff02' => { subnet => '::223.255.255.0/120' }, '::1.1.1.3' => { subnet => '::1.1.1.2/127' }, '::ffff:101:101' => { subnet => '::1.1.1.1/128' }, '::ffff:1.1.1.2' => { subnet => '::1.1.1.2/127' }, '::ffff:101:103' => { subnet => '::1.1.1.2/127' }, '::ffff:dfff:ff02' => { subnet => '::223.255.255.0/120' }, '2001:0:101:101::' => { subnet => '::1.1.1.1/128' }, '2001:0:101:102::' => { subnet => '::1.1.1.2/127' }, '2001:0:101:103::' => { subnet => '::1.1.1.2/127' }, '2001:0:dfff:ff02::' => { subnet => '::223.255.255.0/120' }, '2002:101:101::' => { subnet => '::1.1.1.1/128' }, '2002:101:102::' => { subnet => '::1.1.1.2/127' }, '2002:101:103::' => { subnet => '::1.1.1.2/127' }, '2002:dfff:ff02::' => { subnet => '::223.255.255.0/120' }, '2004::' => { subnet => '2004::/96' }, '2004::9:a' => { subnet => '2004::/96' }, ); for my $address ( sort keys %tests ) { is_deeply( $reader->record_for_address($address), $tests{$address}, "got expected data for $address" ); } } done_testing(); sub _write_tree { my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 24, database_type => 'Test', languages => [ 'en', 'zh' ], description => { en => 'Test Database', zh => 'Test Database Chinese', }, alias_ipv6_to_ipv4 => 1, map_key_type_callback => sub { 'utf8_string' }, remove_reserved_networks => 1, ); # Note: we don't want all of the alias nodes (::ffff:0.0.0.0 and 2002::) # to have adjacent nodes with data, as we want to make sure that the # merging of empty nodes does not merge the alias nodes. my @subnets = qw( ::1.1.1.1/128 ::1.1.1.2/127 ::223.255.255.0/120 ::fffe:0:0/96 2004::/96 ); for my $net (@subnets) { $tree->insert_network( $net, { subnet => $net }, ); } my $filename = $tempdir . '/Test-ipv6-alias.mmdb'; open my $fh, '>', $filename or die $!; $tree->write_tree($fh); close $fh or die $!; return $filename; } Serializer-utf8-round-trip.t100644000000000000 220113321164704 25031 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writeruse strict; use warnings; use Test::Builder; use Test::More; use Encode (); use MaxMind::DB::Reader::Decoder; use MaxMind::DB::Writer::Serializer; { my $tb = Test::Builder->new(); for ( $tb->output, $tb->failure_output, $tb->todo_output ) { binmode $_, ':encoding(UTF-8)' or die $!; } } my $input = "\x{4eba}"; ok( Encode::is_utf8($input), 'input is marked as utf8 in Perl' ); my $serializer = MaxMind::DB::Writer::Serializer->new( map_key_type_callback => sub { } ); $serializer->store_data( utf8_string => $input ); my $buffer = $serializer->buffer(); ## no critic (InputOutput::RequireBriefOpen) open my $fh, '<:raw', $buffer or die $!; my $decoder = MaxMind::DB::Reader::Decoder->new( data_source => $fh, ## no critic (Modules::RequireExplicitInclusion, Subroutines::ProhibitCallsToUnexportedSubs) _data_source_size => bytes::length( ${$buffer} ), ); my $output = $decoder->decode(0); ok( Encode::is_utf8($output), 'output is marked as utf8 in Perl' ); is( $input, $output, "utf-8 string ($input) makes round trip from serializer to decoder safely" ); done_testing(); end_marker.t100644000000000000 63213321164704 25303 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writer/Serializer-typesuse strict; use warnings; use lib 't/lib'; use Test::Bits; use Test::More; use MaxMind::DB::Writer::Serializer; { my $serializer = MaxMind::DB::Writer::Serializer->new( map_key_type_callback => sub { } ); $serializer->_encode_end_marker(); bits_is( ${ $serializer->buffer() }, [ 0b00000000, 0b00000110 ], 'encoding of end_marker type' ); } done_testing(); Tree-iterator-large-dataset.t100644000000000000 142413321164704 25202 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writeruse strict; use warnings; use autodie; use lib 't/lib'; use Test::Requires { JSON => 0, }; use Test::MaxMind::DB::Writer qw( make_tree_from_pairs test_iterator_sanity ); use Test::MaxMind::DB::Writer::Iterator (); use Test::More; use JSON (); { open my $fh, '<', 't/test-data/geolite2-sample.json' or die $!; my $geolite2_data = do { local $/ = undef; <$fh> }; my $records = JSON->new->decode($geolite2_data); close $fh or die $!; my $tree = make_tree_from_pairs( 'network', $records, { alias_ipv6_to_ipv4 => 1 } ); my $iterator = Test::MaxMind::DB::Writer::Iterator->new(6); $tree->iterate($iterator); test_iterator_sanity( $iterator, $tree, 1115, 'tree from geolite2 sample data' ); } done_testing(); utf8_string.t100644000000000000 346313321164704 25475 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writer/Serializer-typesuse strict; use warnings; use lib 't/lib'; use Test::Bits; use Test::Builder; use Test::Fatal; use Test::MaxMind::DB::Common::Data qw( test_cases_for ); use Test::MaxMind::DB::Writer::Serializer qw( test_encoding_of_type ); use Test::More; use MaxMind::DB::Writer::Serializer; { my $tb = Test::Builder->new(); for ( $tb->output, $tb->failure_output, $tb->todo_output ) { binmode $_, ':encoding(UTF-8)' or die $!; } } test_encoding_of_type( utf8_string => test_cases_for('utf8_string') ); my $max_size = ( 2**24 - 1 ) + 65821; _test_long_string( $max_size, [ 0b01011111, 0b11111111, 0b11111111, 0b11111111, ], ); { my $string_too_big = 'x' x ( $max_size + 1 ); my $serializer = MaxMind::DB::Writer::Serializer->new( map_key_type_callback => sub { } ); like( exception { $serializer->_encode_utf8_string($string_too_big) }, qr/\QCannot store 16843037 bytes - max size is 16843036 bytes/, "encoder dies when asked to encode more than $max_size bytes of data" ); } done_testing(); sub _test_long_string { my $length = shift; my $first_4 = shift; my $serializer = MaxMind::DB::Writer::Serializer->new( map_key_type_callback => sub { } ); my $string = 'x' x $length; $serializer->store_data( utf8_string => $string ); bits_is( substr( ${ $serializer->buffer() }, 0, 4 ), $first_4, "first four bytes contain expected value for long string ($length bytes)" ); bits_is( substr( ${ $serializer->buffer() }, 5, 500 ), [ ( ord('x') ) x 500 ], "next 500 bytes contain encoding of x ($length bytes)" ); my $expect = $length + 4; is( length ${ $serializer->buffer() }, $expect, "$length byte string is $expect bytes when encoded" ); } Processor000755000000000000 013321164704 22574 5ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/lib/MaxMind/DB/Writer/TreeVisualizeTree.pm100644000000000000 605713321164704 26075 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/lib/MaxMind/DB/Writer/Tree/Processorpackage MaxMind::DB::Writer::Tree::Processor::VisualizeTree; use strict; use warnings; use namespace::autoclean; our $VERSION = '0.300003'; use Data::Dumper::Concise; use Digest::MD5 qw( md5_hex ); use GraphViz2; use Net::Works::Network; use Moose; has ip_version => ( is => 'ro', isa => 'Int', required => 1, ); has show_full_data_record => ( is => 'ro', isa => 'Bool', default => 0, ); has graph => ( is => 'ro', isa => 'GraphViz2', init_arg => undef, default => sub { GraphViz2->new( global => { directed => 1 } ) }, ); has _labels => ( is => 'ro', init_arg => undef, default => sub { {} }, ); ## no critic (Subroutines::ProhibitManyArgs) sub process_node_record { my $self = shift; my $node_num = shift; my $dir = shift; my $node_ip_num = shift; my $node_prefix_length = shift; my $record_ip_num = shift; my $record_prefix_length = shift; my $record_node_num = shift; $self->graph()->add_edge( from => $self->_label_for_node( $node_num, $node_ip_num, $node_prefix_length ), to => $self->_label_for_node( $record_node_num, $record_ip_num, $record_prefix_length ), label => ( $dir ? 'RIGHT' : 'LEFT' ), ); return 1; } sub process_empty_record { return; } sub process_data_record { my $self = shift; my $node_num = shift; my $dir = shift; my $node_ip_num = shift; my $node_prefix_length = shift; my $record_ip_num = shift; my $record_prefix_length = shift; my $value = shift; $self->graph()->add_edge( from => $self->_label_for_node( $node_num, $node_ip_num, $node_prefix_length ), to => $self->_network( $record_ip_num, $record_prefix_length ) . ' = ' . $self->_data_record_representation($value), label => ( $dir ? 'RIGHT' : 'LEFT' ), ); return 1; } sub _label_for_node { my $self = shift; my $node_num = shift; my $ip_num = shift; my $prefix_length = shift; my $network = $self->_network( $ip_num, $prefix_length ); return $self->_labels()->{$node_num} //= sprintf( 'Node %d - %s (%s - %s)', $node_num, $network->as_string, $network->first()->as_string, $network->last()->as_string, ); } sub _data_record_representation { my $self = shift; my $value = shift; if ( $self->show_full_data_record() ) { return quotemeta( Dumper($value) ); } else { return md5_hex( Dumper($value) ); } } sub _network { my $self = shift; my $ip_num = shift; my $prefix_length = shift; return Net::Works::Network->new_from_integer( integer => $ip_num, prefix_length => $prefix_length, version => $self->ip_version(), ); } __PACKAGE__->meta()->make_immutable(); 1; record-deduplication.t100644000000000000 330613321164704 26277 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writer/Tree-outputuse strict; use warnings; use autodie; use lib 't/lib'; use File::Temp qw( tempdir ); use Test::MaxMind::DB::Writer qw( make_tree_from_pairs ); use Test::More; use Net::Works::Network; my $data1 = { map1 => { map2 => { int1 => 42 }, map3 => { int2 => 84 }, }, array1 => [ 1, 2, 3 ], }; my $data2 = { map1 => { map2 => { int1 => 43 }, map3 => { int2 => 85 }, }, array1 => [ 4, 5, 6 ], }; my $tree = make_tree_from_pairs( 'network', [ [ '1.0.0.0/24' => $data1 ], [ '2.0.0.0/24' => $data1 ], [ '3.0.0.0/24' => $data2 ], [ '4.0.0.0/24' => $data2 ], ], { map_key_type_callback => sub { $_[0] =~ /^(\D+)/ or die "No type for key = $_[0]"; return $1 eq 'array' ? [ 'array', 'uint32' ] : $1 eq 'int' ? 'uint32' : $1; }, }, ); my $calls = 0; { package MaxMind::DB::Writer::Serializer; no warnings 'redefine'; my $sd = __PACKAGE__->can('store_data'); *store_data = sub { my $self = shift; # We want to track calls to this method made from tree.c (not internal # recursive calls). if ( ( caller(0) )[0] ne __PACKAGE__ ) { # There's always one call to store the metadata $calls++ unless $_[1]->{build_epoch}; } return $self->$sd(@_); }; } my $dir = tempdir( CLEANUP => 1 ); open my $fh, '>', "$dir/dedupe.mmdb" or die $!; $tree->write_tree($fh); close $fh or die $!; is( $calls, 2, 'store_data was only called twice because identical record values are deduplicated' ); done_testing(); freeze-then-write-bug.t100644000000000000 250213321164704 26313 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writer/Tree-outputuse strict; use warnings; use Test::Fatal; use Test::More; use File::Temp qw( tempdir ); use MaxMind::DB::Writer::Tree; use Net::Works::Network; my $tempdir = tempdir( CLEANUP => 1 ); # The underlying bug was happening because calling freeze_tree() would call # finalize_tree() internally. Then when write_tree() was called, it would # create IP6->4 alias nodes in the tree, but because the tree though it was # finalized, these new nodes would never get numbered. { my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 6, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test Database', }, # This bug only manifests when this is true alias_ipv6_to_ipv4 => 1, root_data_type => 'utf8_string', map_key_type_callback => sub { }, ); $tree->insert_network( Net::Works::Network->new_from_string( string => '::1.64.22.0/120', ), 'foo', ); $tree->freeze_tree("$tempdir/frozen"); my $output; open my $fh, '>:raw', \$output or die $!; is( exception { $tree->write_tree($fh) }, undef, 'no exception writing tree where an alias overwrote an existing record' ); close $fh or die $!; } done_testing(); __DATA__ freeze-thaw-record-size.t100644000000000000 361213321164704 26644 0ustar00rootroot000000000000MaxMind-DB-Writer-0.300003/t/MaxMind/DB/Writer/Tree-outputuse strict; use warnings; use Test::Fatal; use Test::More; use File::Temp qw( tempdir ); use MaxMind::DB::Writer::Tree; use Net::Works::Network; use Test::Requires { 'MaxMind::DB::Reader' => 0.040000, }; my $tempdir = tempdir( CLEANUP => 1 ); # make a frozen tree on disk with record size 24 { my $tree = MaxMind::DB::Writer::Tree->new( ip_version => 4, record_size => 24, database_type => 'Test', languages => ['en'], description => { en => 'Test Database', }, map_key_type_callback => sub { }, ); $tree->insert_network( Net::Works::Network->new_from_string( string => '1.64.22.0/24', ), { answer => 42 }, ); $tree->insert_network( Net::Works::Network->new_from_string( string => '1.64.23.0/24', ), { ncc => 1701 }, ); $tree->freeze_tree("$tempdir/frozen"); } # unfreeze the tree setting network size to 32, write it as an mmdb { my $tree = MaxMind::DB::Writer::Tree->new_from_frozen_tree( filename => "$tempdir/frozen", map_key_type_callback => sub { 'uint32' }, record_size => 32, ); open my $fh, '>:raw', "$tempdir/mmdb" or die $!; $tree->write_tree($fh); close $fh or die $!; } # load the mmdb, check record size is 32 not 24 { ## no critic (Modules::RequireExplicitInclusion) my $mmdb = MaxMind::DB::Reader->new( file => "$tempdir/mmdb" ); ## use critic my $metadata = $mmdb->metadata; is( $metadata->record_size, 32, 'record size' ); # check that we can still read those IPs correctly is_deeply( $mmdb->record_for_address('1.64.22.123'), { answer => 42 }, 'ip address lookup check 1/2' ); is_deeply( $mmdb->record_for_address('1.64.23.123'), { ncc => 1701 }, 'ip address lookup check 2/2' ); } done_testing();