From: <gb...@us...> - 2003-11-05 00:03:19
|
Update of /cvsroot/zxsync/zXSync/uuidmodule In directory sc8-pr-cvs1:/tmp/cvs-serv22324 Added Files: Makefile uuid-test.py uuidgen.c uuidgen.h Log Message: adding python binding to CoreFoundation's UUID generation routine for use with iCal --- NEW FILE: Makefile --- # a quick and dirty makefile because I can't get xcode to build this properly # # Copyright (C) 2003 Geoff Beier <me...@mo...> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library 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 # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # $Id: Makefile,v 1.1 2003/11/05 00:03:16 gbeier Exp $ # MODULE=uuidgen PYTHON_HEADERLOC=/System/Library/Frameworks/Python.framework/Versions/2.3/include/python2.3 SWIG=/sw/bin/swig SWIGFLAGS=-python PYTHON=/usr/bin/python FRAMEWORKS=-framework Python -framework CoreFoundation CFLAGS+= -I $(PYTHON_HEADERLOC) LDFLAGS=-bundle -bundle_loader $(PYTHON) $(FRAMEWORKS) OBJS=$(MODULE).o $(MODULE)_wrap.o all: _$(MODULE).so $(MODULE)_wrap.c: $(MODULE).h $(SWIG) $(SWIGFLAGS) $(MODULE).h _$(MODULE).so: $(OBJS) $(CC) $(LDFLAGS) $(OBJS) -o _$(MODULE).so clean: rm -f $(OBJS) _$(MODULE).so $(MODULE).py $(MODULE)_wrap.c *.pyc viclean: rm -f *~ --- NEW FILE: uuid-test.py --- #!/usr/bin/env python # # test for python CFUUID binding # # Copyright (C) 2003 Geoff Beier <me...@mo...> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library 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 # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # $Id: uuid-test.py,v 1.1 2003/11/05 00:03:16 gbeier Exp $ # import uuidgen print "CFUUID generated ", uuidgen.newUUID() --- NEW FILE: uuidgen.c --- /* * uuidgen.c - a simple wrapper for the CFUUIDCreate() function so that it can easily be * used with python * * Copyright (C) 2003 Geoff Beier <me...@mo...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * $Id: uuidgen.c,v 1.1 2003/11/05 00:03:16 gbeier Exp $ * */ #include "uuidgen.h" #include <CoreFoundation/CoreFoundation.h> /* * generates a UUID and returns it as a C-style string */ char * newUUID() { char * rv = NULL; CFStringRef uuidString = NULL; CFUUIDRef uuid = NULL; CFIndex len = 0; uuid = CFUUIDCreate( NULL ); if( NULL == uuid ) { return rv; } uuidString = CFUUIDCreateString( NULL, uuid ); if( NULL == uuidString ) { return rv; } len = CFStringGetLength( uuidString ); rv = malloc( (size_t)(len * sizeof(char) + 1) ); if( NULL == rv ) { return rv; } if( !CFStringGetCString( uuidString, rv, len * sizeof(char) + 1, kCFStringEncodingASCII ) ) { free( rv ); rv = NULL; } return rv; } --- NEW FILE: uuidgen.h --- /* * uuidgen.h - python interface to CF UUID function * * * Copyright (C) 2003 Geoff Beier <me...@mo...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * $Id: uuidgen.h,v 1.1 2003/11/05 00:03:16 gbeier Exp $ * */ /*************** SWIG stuff ***************/ #ifdef SWIG %module uuidgen %{ #include "uuidgen.h" %} #endif /****************************************/ /** * newUUID() - uses CF to generate a new UUID and convert it to a C-style string * if my carbon-fu were better I should just wrap the CF stuff up (extend the CF * bridge from MacPython 2.3 and maybe submit a patch to the python crew...) but * this + SWIG is more my speed right now. */ char * newUUID( void ); |