Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Update to Heikki's head #1

Merged
merged 8 commits into from

3 participants

@japeq
Owner

No description provided.

yann-morin-1998 and others added some commits
@japeq japeq merged commit 1987f76 into japeq:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 19, 2012
  1. @yann-morin-1998 @heikkiorsila

    configure: fix python install path

    yann-morin-1998 authored heikkiorsila committed
    Pass the installation prefix to python.
    
    Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Commits on Nov 20, 2012
  1. @heikkiorsila
  2. @heikkiorsila
  3. @heikkiorsila

    libbencode: Type safety-check for list and dict macro iterators [PREV…

    heikkiorsila authored
    …ENTIVE]
    
    NULL dereference occurs if inappropriate type is passed for the iterator macro.
  4. @heikkiorsila
Commits on Jan 28, 2013
  1. @heikkiorsila

    configure/Makefile.in: Implement configurable Python interpreter and …

    heikkiorsila authored
    …C compiler [PERFECTIVE]
    
    Note, --home makes Python installer to install Python at user's local packages
    inside $HOME directory (e.g. $HOME/.local/lib/pythonXXX/site-packages/).
Commits on May 4, 2013
  1. @heikkiorsila
  2. @heikkiorsila
This page is out of date. Refresh to see the latest.
Showing with 123 additions and 34 deletions.
  1. +14 −5 Makefile.in
  2. +2 −2 bencode.c
  3. +84 −20 configure
  4. +23 −7 include/bencodetools/bencode.h
View
19 Makefile.in
@@ -6,12 +6,18 @@ PREFIX = {PREFIX}
LIBPATH = {LIBPATH}
LIBNAME = {LIBNAME}
SHAREDNAMEFLAG = {SHAREDNAMEFLAG}
-
+PYTHON = {PYTHON}
PYTHON_INSTALL_OPTION = {PYTHON_INSTALL_OPTION}
+COMPILE_TARGETS = {COMPILE_TARGETS}
+INSTALL_TARGETS = {INSTALL_TARGETS}
+
LIBMODULES = bencode.o
-all: $(LIBNAME) bencodetest bencat
+all: $(COMPILE_TARGETS)
+
+compile-c: $(LIBNAME) bencodetest bencat
+compile-python:
$(LIBNAME): $(LIBMODULES)
$(CC) -shared $(SHAREDNAMEFLAG) -o "$@" $(LIBMODULES)
@@ -31,20 +37,23 @@ check: bencodetest
@echo
@echo "All tests successful" #
-install:
+install-c:
@echo "Installing C library"
@echo
mkdir -p -m 755 "$(PREFIX)/lib" "$(PREFIX)/include/bencodetools" "$(PREFIX)/bin"
install -m 644 include/bencodetools/*.h "$(PREFIX)/include/bencodetools/"
install -m 644 $(LIBNAME) "$(LIBPATH)"
install bencat "$(PREFIX)/bin/"
+
+install-python:
@echo
@echo "Installing Python packages"
- python setup.py install "$(PYTHON_INSTALL_OPTION)"
+ $(PYTHON) setup.py install $(PYTHON_INSTALL_OPTION)
+
+install: $(INSTALL_TARGETS)
%.o: %.c
$(CC) $(CFLAGS) -c $<
clean:
rm -f *.o *.so bencodetest bencat
-
View
4 bencode.c
@@ -247,7 +247,7 @@ static struct bencode *clone_dict(const struct bencode_dict *d)
struct bencode *newdict = ben_dict();
if (newdict == NULL)
return NULL;
- ben_dict_for_each(key, value, pos, d) {
+ ben_dict_for_each(key, value, pos, (const struct bencode *) d) {
newkey = ben_clone(key);
newvalue = ben_clone(value);
if (newkey == NULL || newvalue == NULL) {
@@ -278,7 +278,7 @@ static struct bencode *clone_list(const struct bencode_list *list)
struct bencode *newlist = ben_list();
if (newlist == NULL)
return NULL;
- ben_list_for_each(value, pos, list) {
+ ben_list_for_each(value, pos, (const struct bencode *) list) {
newvalue = ben_clone(value);
if (newvalue == NULL)
goto error;
View
104 configure
@@ -2,31 +2,59 @@
prefix=/usr/local
libpath=""
+
+cc="$CC"
+if [[ -z "$cc" ]] ; then
+ cc=gcc
+fi
+no_c=""
+
python_install_option=""
+python="python"
+no_python=""
+
+targets=""
for opt in "$@" ; do
case $opt in
--lib-path=*)
- libpath=$(echo $opt | sed -n 's/--lib-path=\(.*\)/\1/p')
+ libpath=$(echo "$opt" | sed -n 's/--lib-path=\(.*\)/\1/p')
;;
--prefix=*)
- prefix=`echo $opt | sed -n 's/--prefix=\(.*\)/\1/p'`
+ prefix=`echo "$opt" | sed -n 's/--prefix=\(.*\)/\1/p'`
;;
--package-prefix=*)
- packageprefix=`echo $opt | sed -n 's/--package-prefix=\(.*\)/\1/p'`
+ packageprefix=`echo "$opt" | sed -n 's/--package-prefix=\(.*\)/\1/p'`
;;
--home)
prefix="$HOME"
LDFLAGS="-L$HOME/lib -Wl,-rpath,$HOME/lib"
python_install_option="--user"
;;
+ --c-compiler=*)
+ cc=`echo "$opt" | sed -n 's/--c-compiler=\(.*\)/\1/p'`
+ ;;
+ --python=*)
+ python=`echo "$opt" | sed -n 's/--python=\(.*\)/\1/p'`
+ ;;
+ --without-c)
+ no_c="true"
+ ;;
+ --without-python)
+ no_python="true"
+ ;;
--help)
echo ""
echo "Valid options are:"
- echo "--lib-path=dir Install libraries to 'dir'"
- echo "--prefix=dir Install program to prefix 'dir'"
+ echo "--lib-path=dir Install libraries to 'dir'."
+ echo "--prefix=dir Install program to prefix 'dir'."
echo "--package-prefix=dest Pretend to install to the prefix,"
- echo " but copy files to 'dest/prefix' on make install"
+ echo " but copy files to 'dest/prefix' on make install."
+ echo "--home Install bencode libraries to $HOME directory."
+ echo "--c-compiler=exe Use given C compiler."
+ echo "--python=exe Use given Python interpreter for installation."
+ echo "--without-c Don't install C library."
+ echo "--without-python Don't install Python library."
exit
;;
*)
@@ -35,21 +63,45 @@ for opt in "$@" ; do
esac
done
-if test -z "$libpath" ; then
- if test -d "$prefix/lib64"; then
+if [[ -n $no_python ]] ; then
+ python="/bin/false"
+fi
+"$python" --version >/dev/null 2>/dev/null
+if [[ $? = 0 ]] ; then
+ targets="python $targets"
+else
+ if [[ -z $no_python ]] ; then
+ echo "Python interpreter not found: $python"
+ exit 1
+ fi
+ python=""
+fi
+
+if [[ -z "$libpath" ]] ; then
+ if [[ -d "$prefix/lib64" ]] ; then
libpath="$prefix/lib64"
else
libpath="$prefix/lib"
fi
fi
-if test ! -z "$packageprefix" ; then
- prefix="$packageprefix/$prefix"
- libpath="$packageprefix/$libpath"
+if [[ ! -z "$packageprefix" ]] ; then
+ prefix="$packageprefix/$prefix"
+ libpath="$packageprefix/$libpath"
fi
-if test -z "$CC" ; then
- CC=gcc
+if [[ -n $no_c ]] ; then
+ cc="/bin/false"
+fi
+"$cc" --version >/dev/null 2>/dev/null
+if [[ $? = 0 ]] ; then
+ targets="c $targets"
+else
+ if [[ -z $no_c ]] ; then
+ echo "C compiler not found: $cc"
+ exit 1
+ fi
+ cc=""
fi
# Linux shared library config
@@ -58,15 +110,22 @@ SHAREDFLAG="-shared"
LIBNAME="libbencodetools.so"
SHAREDNAMEFLAG="-Wl,-soname,$LIBNAME"
if test "x$(uname)" = "xDarwin" ; then
- # Mac OS X shared library config
- SHAREDLIBRARYFLAGS="-dynamic -bundle -undefined suppress -force_flat_namespace"
- SHAREDFLAG="-dynamiclib"
- LIBNAME="libbencodetools.dylib"
- SHAREDNAMEFLAG="-install_name \$(PREFIX)/lib/$LIBNAME"
+ # Mac OS X shared library config
+ SHAREDLIBRARYFLAGS="-dynamic -bundle -undefined suppress -force_flat_namespace"
+ SHAREDFLAG="-dynamiclib"
+ LIBNAME="libbencodetools.dylib"
+ SHAREDNAMEFLAG="-install_name \$(PREFIX)/lib/$LIBNAME"
fi
+compile_targets=""
+install_targets=""
+for target in $targets ; do
+ compile_targets="$compile_targets compile-$target"
+ install_targets="$install_targets install-$target"
+done
+
sed -e "s|{PREFIX}|$prefix|g" \
- -e "s|{CC}|$CC|g" \
+ -e "s|{CC}|$cc|g" \
-e "s|{LIBPATH}|$libpath|g" \
-e "s|{CFLAGS}|$CFLAGS|g" \
-e "s|{LDFLAGS}|$LDFLAGS|g" \
@@ -74,12 +133,17 @@ sed -e "s|{PREFIX}|$prefix|g" \
-e "s|{SHAREDFLAG}|$SHAREDFLAG|g" \
-e "s|{SHAREDNAMEFLAG}|$SHAREDNAMEFLAG|g" \
-e "s|{LIBNAME}|$LIBNAME|g" \
+ -e "s|{PYTHON}|$python|g" \
-e "s|{PYTHON_INSTALL_OPTION}|$python_install_option|g" \
+ -e "s|{COMPILE_TARGETS}|$compile_targets|g" \
+ -e "s|{INSTALL_TARGETS}|$install_targets|g" \
< Makefile.in > Makefile
echo
echo "Install prefix: $prefix"
echo "Library path: $libpath"
-echo "Compiler: $CC"
+echo "Compiler: $cc"
+echo "Python: $python"
+echo "Targets: $targets"
echo
echo "Configure successful"
View
30 include/bencodetools/bencode.h
@@ -225,7 +225,13 @@ void *ben_encode(size_t *len, const struct bencode *b);
*/
size_t ben_encode2(char *data, size_t maxlen, const struct bencode *b);
-/* You must use ben_free() for all allocated bencode structures after use */
+/*
+ * You must use ben_free() for all allocated bencode structures after use.
+ * If b == NULL, ben_free does nothing.
+ *
+ * ben_free() frees all the objects contained within the bencoded structure.
+ * It recursively iterates over lists and dictionaries and frees objects.
+ */
void ben_free(struct bencode *b);
long long ben_str_hash(const struct bencode *b);
@@ -572,10 +578,19 @@ static inline const char *ben_str_val(const struct bencode *b)
* using ben_list_pop_current().
*
* pos is a size_t.
+ *
+ * Example:
+ *
+ * size_t pos;
+ * struct bencode *list = xxx;
+ * struct bencode *value;
+ * ben_list_for_each(value, pos, list) {
+ * inspect(value);
+ * }
*/
#define ben_list_for_each(value, pos, l) \
- for ((pos) = 0; \
- (pos) < ((const struct bencode_list *) (l))->n && \
+ for ((pos) = (size_t) 0; \
+ (pos) < (ben_list_const_cast(l))->n && \
((value) = ((const struct bencode_list *) (l))->values[(pos)]) != NULL ; \
(pos)++)
@@ -588,11 +603,12 @@ static inline const char *ben_str_val(const struct bencode *b)
* Filter out all items from list whose string value does not begin with "foo".
*
* ben_list_for_each(value, pos, list) {
- * if (strncmp(ben_str_val(value), "foo", 3) != 0)
- * ben_free(ben_list_pop_current(&pos, list));
+ * if (strncmp(ben_str_val(value), "foo", 3) != 0)
+ * ben_free(ben_list_pop_current(&pos, list));
* }
*/
-static inline struct bencode *ben_list_pop_current(struct bencode *list, size_t *pos)
+static inline struct bencode *ben_list_pop_current(struct bencode *list,
+ size_t *pos)
{
struct bencode *value = ben_list_pop(list, *pos);
(*pos)--;
@@ -619,7 +635,7 @@ static inline struct bencode *ben_list_pop_current(struct bencode *list, size_t
*/
#define ben_dict_for_each(bkey, bvalue, pos, d) \
for ((pos) = 0; \
- (pos) < ((const struct bencode_dict *) (d))->n && \
+ (pos) < (ben_dict_const_cast(d))->n && \
((bkey) = ((const struct bencode_dict *) (d))->nodes[(pos)].key) != NULL && \
((bvalue) = ((const struct bencode_dict *) (d))->nodes[(pos)].value) != NULL; \
(pos)++)
Something went wrong with that request. Please try again.