Author: dagolden
Date: Thu Jul 23 10:41:15 2009
New Revision: 13110
Added:
ExtUtils-ParseXS/trunk/t/bugs/
ExtUtils-ParseXS/trunk/t/bugs.t (contents, props changed)
ExtUtils-ParseXS/trunk/t/bugs/RT48104.xs
ExtUtils-ParseXS/trunk/t/bugs/typemap
ExtUtils-ParseXS/trunk/t/include/
ExtUtils-ParseXS/trunk/t/include/nsUniversalDetector.h (contents, props
changed)
ExtUtils-ParseXS/trunk/t/include/nscore.h (contents, props changed)
Log:
Add tests demonstrating RT#48104
Added: ExtUtils-ParseXS/trunk/t/bugs.t
==============================================================================
--- (empty file)
+++ ExtUtils-ParseXS/trunk/t/bugs.t Thu Jul 23 10:41:15 2009
@@ -0,0 +1,95 @@
+#!/usr/bin/perl
+
+BEGIN {
+ if ($ENV{PERL_CORE}) {
+ chdir 't' if -d 't';
+ chdir '../lib/ExtUtils/ParseXS'
+ or die "Can't chdir to lib/ExtUtils/ParseXS: $!";
+ @INC = qw(../.. ../../.. .);
+ }
+}
+use strict;
+use Test::More;
+use Config;
+use DynaLoader;
+use ExtUtils::CBuilder;
+
+# paths relative to t/
+my @bugs = (
+ {
+ xs_options => {
+ filename => 'bugs/RT48104.xs',
+ 'C++' => 1,
+ typemap => 'typemap',
+ },
+ cb_options => {
+ extra_compiler_flags => ['-x', 'c++', '-Iinclude'],
+ },
+ },
+);
+
+plan tests => 1 + 3 * @bugs;
+
+my ($source_file, $obj_file, $lib_file);
+
+require_ok( 'ExtUtils::ParseXS' );
+ExtUtils::ParseXS->import('process_file');
+
+chdir 't' or die "Can't chdir to t/, $!";
+
+use Carp; $SIG{__WARN__} = \&Carp::cluck;
+
+#########################
+
+for my $bug ( @bugs ) {
+
+ $source_file = 'XSTest.c';
+
+ # Try sending to file
+ process_file(output => $source_file, prototypes => 0, %{$bug->{xs_options}});
+ ok -e $source_file, "Create an output file";
+
+ my $quiet = $ENV{PERL_CORE} && !$ENV{HARNESS_ACTIVE};
+ my $b = ExtUtils::CBuilder->new(quiet => $quiet);
+
+ SKIP: {
+ skip "no compiler available", 2
+ if ! $b->have_compiler;
+ $obj_file = $b->compile( source => $source_file, %{$bug->{cb_options}} );
+ ok $obj_file;
+ ok -e $obj_file, "Make sure $obj_file exists";
+ }
+
+# SKIP: {
+# skip "no dynamic loading", 5
+# if !$b->have_compiler || !$Config{usedl};
+# my $module = 'XSTest';
+# $lib_file = $b->link( objects => $obj_file, module_name => $module );
+# ok $lib_file;
+# ok -e $lib_file, "Make sure $lib_file exists";
+#
+# eval {require XSTest};
+# is $@, '';
+# ok XSTest::is_even(8);
+# ok !XSTest::is_even(9);
+#
+# # Win32 needs to close the DLL before it can unlink it, but unfortunately
+# # dl_unload_file was missing on Win32 prior to perl change #24679!
+# if ($^O eq 'MSWin32' and defined &DynaLoader::dl_unload_file) {
+# for (my $i = 0; $i < @DynaLoader::dl_modules; $i++) {
+# if ($DynaLoader::dl_modules[$i] eq $module) {
+# DynaLoader::dl_unload_file($DynaLoader::dl_librefs[$i]);
+# last;
+# }
+# }
+# }
+# }
+}
+
+unless ($ENV{PERL_NO_CLEANUP}) {
+ for ( $obj_file, $lib_file, $source_file) {
+ next unless defined $_;
+ 1 while unlink $_;
+ }
+}
+
Added: ExtUtils-ParseXS/trunk/t/bugs/RT48104.xs
==============================================================================
--- (empty file)
+++ ExtUtils-ParseXS/trunk/t/bugs/RT48104.xs Thu Jul 23 10:41:15 2009
@@ -0,0 +1,115 @@
+// ***** BEGIN LICENSE BLOCK *****
+// Version: MPL 1.1/GPL 2.0/LGPL 2.1
+//
+// The contents of this file are subject to the Mozilla Public License Version
+// 1.1 (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+// http://www.mozilla.org/MPL/
+//
+// Software distributed under the License is distributed on an "AS IS" basis,
+// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+// for the specific language governing rights and limitations under the
+// License.
+//
+// The Original Code is Encode::Detect wrapper
+//
+// The Initial Developer of the Original Code is
+// Proofpoint, Inc.
+// Portions created by the Initial Developer are Copyright (C) 2005
+// the Initial Developer. All Rights Reserved.
+//
+// Contributor(s):
+//
+// Alternatively, the contents of this file may be used under the terms of
+// either the GNU General Public License Version 2 or later (the "GPL"), or
+// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+// in which case the provisions of the GPL or the LGPL are applicable instead
+// of those above. If you wish to allow use of your version of this file only
+// under the terms of either the GPL or the LGPL, and not to allow others to
+// use your version of this file under the terms of the MPL, indicate your
+// decision by deleting the provisions above and replace them with the notice
+// and other provisions required by the GPL or the LGPL. If you do not delete
+// the provisions above, a recipient may use your version of this file under
+// the terms of any one of the MPL, the GPL or the LGPL.
+//
+// ***** END LICENSE BLOCK *****
+
+extern "C" {
+#define PERL_NO_GET_CONTEXT /* we want efficiency */
+#include "EXTERN.h"
+#include "perl.h"
+
+// work around perlbug #39634
+#if __GNUC__ == 3 && __GNUC_MINOR__ <= 3
+#undef HASATTRIBUTE_UNUSED
+#endif
+
+#include "XSUB.h"
+}
+
+#include "nscore.h"
+#include "nsUniversalDetector.h"
+
+class Detector: public nsUniversalDetector {
+ public:
+ Detector() {};
+ virtual ~Detector() {}
+ const char *getresult() { return mDetectedCharset; }
+ virtual void Reset() { this->nsUniversalDetector::Reset(); }
+ protected:
+ virtual void Report(const char* aCharset) { mDetectedCharset =
aCharset; }
+};
+
+
+MODULE = Encode::Detect::Detector PACKAGE =
Encode::Detect::Detector
+PROTOTYPES: ENABLE
+
+
+Detector *
+Detector::new()
+
+void
+Detector::DESTROY()
+
+int
+Detector::handle(SV *buf)
+ CODE:
+ STRLEN len;
+ char *ptr = SvPV(buf, len);
+ RETVAL = THIS->HandleData(ptr, len);
+ OUTPUT:
+ RETVAL
+
+void
+Detector::eof()
+ CODE:
+ THIS->DataEnd();
+
+void
+Detector::reset()
+ CODE:
+ THIS->Reset();
+
+const char *
+Detector::getresult()
+ CODE:
+ RETVAL = THIS->getresult();
+ OUTPUT:
+ RETVAL
+
+
+const char *
+detect(buf)
+ SV *buf
+ CODE:
+ STRLEN len;
+ char *ptr = SvPV(buf, len);
+
+ Detector *det = new Detector;
+ det->HandleData(ptr, len);
+ det->DataEnd();
+ RETVAL = det->getresult();
+ delete det;
+ OUTPUT:
+ RETVAL
+
Added: ExtUtils-ParseXS/trunk/t/bugs/typemap
==============================================================================
--- (empty file)
+++ ExtUtils-ParseXS/trunk/t/bugs/typemap Thu Jul 23 10:41:15 2009
@@ -0,0 +1,18 @@
+TYPEMAP
+Detector * O_OBJECT
+
+INPUT
+O_OBJECT
+ if (sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVMG)) {
+ $var = ($type)SvIV((SV*)SvRV( $arg ));
+ } else {
+ warn(\"${Package}::$func_name() -- $var is not a blessed SV
reference\");
+ XSRETURN_UNDEF;
+ }
+
+OUTPUT
+# The Perl object is blessed into 'CLASS', which should be a
+# char * having the name of the package for the blessing.
+O_OBJECT
+ sv_setref_pv($arg, CLASS, (void*)$var);
+
Added: ExtUtils-ParseXS/trunk/t/include/nsUniversalDetector.h
==============================================================================
--- (empty file)
+++ ExtUtils-ParseXS/trunk/t/include/nsUniversalDetector.h Thu Jul 23
10:41:15 2009
@@ -0,0 +1,75 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Communicator client code.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef nsUniversalDetector_h__
+#define nsUniversalDetector_h__
+
+class nsCharSetProber;
+
+#define NUM_OF_CHARSET_PROBERS 3
+
+typedef enum {
+ ePureAscii = 0,
+ eEscAscii = 1,
+ eHighbyte = 2
+} nsInputState;
+
+class nsUniversalDetector {
+public:
+ nsUniversalDetector();
+ virtual ~nsUniversalDetector();
+ virtual nsresult HandleData(const char* aBuf, PRUint32 aLen);
+ virtual void DataEnd(void);
+
+protected:
+ virtual void Report(const char* aCharset) = 0;
+ virtual void Reset();
+ nsInputState mInputState;
+ PRBool mDone;
+ PRBool mInTag;
+ PRBool mStart;
+ PRBool mGotData;
+ char mLastChar;
+ const char * mDetectedCharset;
+ PRInt32 mBestGuess;
+
+ nsCharSetProber *mCharSetProbers[NUM_OF_CHARSET_PROBERS];
+ nsCharSetProber *mEscCharSetProber;
+};
+
+#endif
+
Added: ExtUtils-ParseXS/trunk/t/include/nscore.h
==============================================================================
--- (empty file)
+++ ExtUtils-ParseXS/trunk/t/include/nscore.h Thu Jul 23 10:41:15 2009
@@ -0,0 +1,20 @@
+#ifndef INCLUDED_NSCORE_H
+#define INCLUDED_NSCORE_H
+
+typedef short PRInt16;
+typedef unsigned short PRUint16;
+
+typedef int PRInt32;
+typedef unsigned PRUint32;
+
+typedef int PRBool;
+#define PR_TRUE 1
+#define PR_FALSE 0
+
+#define nsnull 0
+
+typedef PRUint32 nsresult;
+#define NS_OK 0
+#define NS_ERROR_OUT_OF_MEMORY ((nsresult)(0x8007000eL))
+
+#endif /* INCLUDED_NSCORE_H */