Skip to content

Commit

Permalink
Fixes for OSX; upstream r136; 2.4 support.
Browse files Browse the repository at this point in the history
 * Ensure that 'ppc' platform is not built on OSX i386/x86_64 machines.
   Avoid compiling Platform.cpp as SetAffinity is not used.
 * Synced with upstream r136. None of the changes affect this extension.
 * Now builds for Python version 2.4.  Tested versions 2.4 through 3.1.
 * Unified test case.
 * Added quick usage example to the README.
 * Bumped version to 0.136.1.
 * Extension and project version numbers now match.

Thanks to @jbenet for the initial commit on which this is based.
  • Loading branch information
phensley committed Jun 18, 2011
1 parent 7da2395 commit 96d8b9b
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 38 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,17 @@ variants.

License: MIT License

Usage
-----

>>> import smhasher
>>> [k for k in dir(smhasher) if k[0] == 'm']
['murmur3_x64_128', 'murmur3_x64_64', 'murmur3_x86_128', 'murmur3_x86_64']

>>> smhasher.murmur3_x86_128('hello')
213030289162235495270783145757721615258L

>>> seed = 1138
>>> smhasher.murmur3_x86_128('hello', seed)
94758481705480737162820094006203962724L

17 changes: 13 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@

import os
import platform
import sys
from distutils.core import setup, Extension

# version number is x.[upstream svn revision].release until upstream
# creates a formal version number.
VERSION = '0.135.4'
VERSION = '0.136.1'

# avoid building universal binary (ppc) on osx non-ppc platforms
if sys.platform == 'darwin':
arch = platform.machine()
if arch in ('i386', 'x86_64'):
os.environ['ARCHFLAGS'] = '-arch i386 -arch x86_64'

smhasher_ext = Extension('smhasher',
sources=[
'smhasher.cpp',
'smhasher/MurmurHash3.cpp',
'smhasher/Platform.cpp'
],
],
include_dirs=['smhasher'],
define_macros=[('MODULE_VERSION', '"%s"' % VERSION)])


setup(
name='smhasher',
version=0.1,
version=VERSION,
description='Python extension for smhasher hash functions',
ext_modules=[smhasher_ext]
)
Expand Down
7 changes: 7 additions & 0 deletions smhasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
#include "MurmurHash3.h"


#if PY_VERSION_HEX < 0x02050000
typedef int Py_ssize_t;
#define PY_SSIZE_T_MAX INT_MAX
#define PY_SSIZE_T_MIN INT_MIN
#endif


static PyObject *
_py_murmur3_128(PyObject *self, PyObject *args, int x86, int size)
{
Expand Down
2 changes: 1 addition & 1 deletion smhasher/MurmurHash3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void MurmurHash3_x86_32 ( const void * key, int len,
case 3: k1 ^= tail[2] << 16;
case 2: k1 ^= tail[1] << 8;
case 1: k1 ^= tail[0];
k1 *= c1; k1 = ROTL32(k1,16); k1 *= c2; h1 ^= k1;
k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
};

//----------
Expand Down
2 changes: 1 addition & 1 deletion smhasher/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ HashInfo g_hashes[] =

// MurmurHash3

{ MurmurHash3_x86_32, 32, 0x3252D141, "Murmur3A", "MurmurHash3 for x86, 32-bit" },
{ MurmurHash3_x86_32, 32, 0xB0F57EE3, "Murmur3A", "MurmurHash3 for x86, 32-bit" },
{ MurmurHash3_x86_128, 128, 0xB3ECE62A, "Murmur3C", "MurmurHash3 for x86, 128-bit" },
{ MurmurHash3_x64_128, 128, 0x6384BA69, "Murmur3F", "MurmurHash3 for x64, 128-bit" },

Expand Down
File renamed without changes.
32 changes: 0 additions & 32 deletions test_2x.py

This file was deleted.

0 comments on commit 96d8b9b

Please sign in to comment.