[80963] branches/gsoc11-post-destroot/base/src
fotanus at macports.org
fotanus at macports.org
Thu Jul 21 22:10:07 PDT 2011
Revision: 80963
http://trac.macports.org/changeset/80963
Author: fotanus at macports.org
Date: 2011-07-21 22:10:06 -0700 (Thu, 21 Jul 2011)
Log Message:
-----------
Now macho.c functions responds to non-binary files
this is needed in order to skip non binary files.
also, did some code cleanup
Modified Paths:
--------------
branches/gsoc11-post-destroot/base/src/pextlib1.0/macho.c
branches/gsoc11-post-destroot/base/src/port1.0/portcheckdestroot.tcl
Modified: branches/gsoc11-post-destroot/base/src/pextlib1.0/macho.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/macho.c 2011-07-22 00:16:24 UTC (rev 80962)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/macho.c 2011-07-22 05:10:06 UTC (rev 80963)
@@ -19,7 +19,6 @@
#include <tcl.h>
#include "macho.h"
-Tcl_Interp *interp2;
typedef struct macho_input {
const void *data;
size_t length;
@@ -57,7 +56,7 @@
}
/* Parse a Mach-O header */
-Tcl_Obj * list_macho_dlibs_l (macho_input_t *input, Tcl_Obj * dlibs) {
+Tcl_Obj * list_macho_dlibs_l(macho_input_t *input, Tcl_Interp * interp, Tcl_Obj * dlibs) {
/* Read the file type. */
const uint32_t *magic = macho_read(input, input->data, sizeof(uint32_t));
@@ -78,7 +77,7 @@
if (magic == NULL)
- return TCL_ERROR;
+ return (Tcl_Obj *)TCL_ERROR;
switch (*magic) {
case MH_CIGAM:
@@ -117,7 +116,7 @@
break;
default:
- return TCL_ERROR;
+ return (Tcl_Obj *)TCL_ERROR;
}
/* Parse universal file. */
@@ -141,7 +140,7 @@
return false;
/* Parse the architecture's Mach-O header */
- if (!list_macho_dlibs_l(&arch_input,dlibs))
+ if (!list_macho_dlibs_l(&arch_input, interp, dlibs))
return false;
}
@@ -154,32 +153,39 @@
/* Parse the Mach-O load commands */
cmd = macho_offset(input, header, header_size, sizeof(struct load_command));
if (cmd == NULL)
- return TCL_ERROR;
+ return (Tcl_Obj *)TCL_ERROR;
ncmds = swap32(header->ncmds);
/* Iterate over the load commands */
for (i = 0; i < ncmds; i++) {
/* Load the full command */
uint32_t cmdsize = swap32(cmd->cmdsize);
+ uint32_t cmd_type = swap32(cmd->cmd);
+ size_t pathlen;
+ const void * pathptr;
+ char * path;
+ size_t namelen;
+ const void *nameptr;
+ char *name;
+
cmd = macho_read(input, cmd, cmdsize);
if (cmd == NULL)
- return TCL_ERROR;
+ return (Tcl_Obj *)TCL_ERROR;
/* Handle known types */
- uint32_t cmd_type = swap32(cmd->cmd);
switch (cmd_type) {
case LC_RPATH: {
/* Fetch the path */
if (cmdsize < sizeof(struct rpath_command)) {
- return TCL_ERROR;
+ return (Tcl_Obj *)TCL_ERROR;
}
- size_t pathlen = cmdsize - sizeof(struct rpath_command);
- const void *pathptr = macho_offset(input, cmd, sizeof(struct rpath_command), pathlen);
+ pathlen = cmdsize - sizeof(struct rpath_command);
+ pathptr = macho_offset(input, cmd, sizeof(struct rpath_command), pathlen);
if (pathptr == NULL)
- return TCL_ERROR;
+ return (Tcl_Obj *)TCL_ERROR;
- char *path = malloc(pathlen);
+ path = malloc(pathlen);
strlcpy(path, pathptr, pathlen);
free(path);
break;
@@ -189,23 +195,21 @@
case LC_LOAD_WEAK_DYLIB:
case LC_REEXPORT_DYLIB:
case LC_LOAD_DYLIB: {
- const struct dylib_command *dylib_cmd = (const struct dylib_command *) cmd;
-
/* Extract the install name */
if (cmdsize < sizeof(struct dylib_command)) {
- return TCL_ERROR;
+ return (Tcl_Obj *)TCL_ERROR;
}
- size_t namelen = cmdsize - sizeof(struct dylib_command);
- const void *nameptr = macho_offset(input, cmd, sizeof(struct dylib_command), namelen);
+ namelen = cmdsize - sizeof(struct dylib_command);
+ nameptr = macho_offset(input, cmd, sizeof(struct dylib_command), namelen);
if (nameptr == NULL)
- return TCL_ERROR;
+ return (Tcl_Obj *)TCL_ERROR;
- char *name = malloc(namelen);
+ name = malloc(namelen);
strlcpy(name, nameptr, namelen);
/* This is a dyld library identifier */
- Tcl_ListObjAppendElement(interp2, dlibs, Tcl_NewStringObj(name, -1));
+ Tcl_ListObjAppendElement(interp, dlibs, Tcl_NewStringObj(name, -1));
free(name);
break;
@@ -218,31 +222,34 @@
/* Load the next command */
cmd = macho_offset(input, cmd, cmdsize, sizeof(struct load_command));
if (cmd == NULL)
- return TCL_ERROR;
+ return (Tcl_Obj *)TCL_ERROR;
}
return dlibs;
}
-Tcl_Obj * list_macho_dlibs(macho_input_t *input) {
- return list_macho_dlibs_l(input, Tcl_NewListObj(0,NULL));
+Tcl_Obj * list_macho_dlibs(macho_input_t *input, Tcl_Interp *interp) {
+ return list_macho_dlibs_l(input, interp, Tcl_NewListObj(0,NULL));
}
/* List Mach-O archs */
-Tcl_Obj * list_macho_archs_l(macho_input_t *input, Tcl_Obj * archs_list) {
+Tcl_Obj * list_macho_archs_l(macho_input_t *input, Tcl_Interp *interp, Tcl_Obj * archs_list) {
+ const struct mach_header *header;
+ const struct mach_header_64 *header64;
+ size_t header_size;
+ const NXArchInfo *archInfo;
+ const struct fat_header *fat_header;
+
+ /* Parse the Mach-O header */
+ bool universal = false;
+ uint32_t (*swap32)(uint32_t) = macho_nswap32;
+
/* Read the file type. */
const uint32_t *magic = macho_read(input, input->data, sizeof(uint32_t));
if (magic == NULL)
return false;
- /* Parse the Mach-O header */
- bool universal = false;
- uint32_t (*swap32)(uint32_t) = macho_nswap32;
- const struct mach_header *header;
- const struct mach_header_64 *header64;
- size_t header_size;
- const struct fat_header *fat_header;
switch (*magic) {
case MH_CIGAM:
@@ -253,7 +260,7 @@
header_size = sizeof(*header);
header = macho_read(input, input->data, header_size);
if (header == NULL) {
- return TCL_ERROR;
+ return (Tcl_Obj *)TCL_ERROR;
}
break;
@@ -266,7 +273,7 @@
header_size = sizeof(*header64);
header64 = macho_read(input, input->data, sizeof(*header64));
if (header64 == NULL)
- return TCL_ERROR;
+ return (Tcl_Obj *)TCL_ERROR;
/* The 64-bit header is a direct superset of the 32-bit header */
header = (struct mach_header *) header64;
@@ -280,53 +287,61 @@
break;
default:
- return TCL_ERROR;
+ return (Tcl_Obj *)TCL_ERROR;
}
/* Parse universal file. */
if (universal) {
uint32_t nfat = OSSwapBigToHostInt32(fat_header->nfat_arch);
const struct fat_arch *archs = macho_offset(input, fat_header, sizeof(struct fat_header), sizeof(struct fat_arch));
+ uint32_t i;
+ const struct fat_arch *arch;
+ macho_input_t arch_input;
+
if (archs == NULL)
- return TCL_ERROR;
+ return (Tcl_Obj *)TCL_ERROR;
- uint32_t i;
for (i = 0; i < nfat; i++) {
- const struct fat_arch *arch = macho_read(input, archs + i, sizeof(struct fat_arch));
+ arch = macho_read(input, archs + i, sizeof(struct fat_arch));
if (arch == NULL)
- return TCL_ERROR;
+ return (Tcl_Obj *)TCL_ERROR;
/* Fetch a pointer to the architecture's Mach-O header. */
- macho_input_t arch_input;
arch_input.length = OSSwapBigToHostInt32(arch->size);
arch_input.data = macho_offset(input, input->data, OSSwapBigToHostInt32(arch->offset), arch_input.length);
if (arch_input.data == NULL)
- return TCL_ERROR;
+ return (Tcl_Obj *)TCL_ERROR;
/* Parse the architecture's Mach-O header */
- if (!list_macho_archs_l(&arch_input, archs_list))
- return TCL_ERROR;
+ if (!list_macho_archs_l(&arch_input, interp, archs_list))
+ return (Tcl_Obj *)TCL_ERROR;
}
return archs_list;
}
/* Fetch the arch name */
- const NXArchInfo *archInfo = NXGetArchInfoFromCpuType(swap32(header->cputype), swap32(header->cpusubtype));
+ archInfo = NXGetArchInfoFromCpuType(swap32(header->cputype), swap32(header->cpusubtype));
if (archInfo != NULL) {
- Tcl_ListObjAppendElement(interp2, archs_list, Tcl_NewStringObj(archInfo->name,-1));
+ Tcl_ListObjAppendElement(interp, archs_list, Tcl_NewStringObj(archInfo->name,-1));
}
return archs_list;
}
-Tcl_Obj * list_macho_archs(macho_input_t *input) {
- return list_macho_archs_l(input, Tcl_NewListObj(0,NULL));
+Tcl_Obj * list_macho_archs(macho_input_t *input, Tcl_Interp *interp) {
+ return list_macho_archs_l(input, interp, Tcl_NewListObj(0,NULL));
}
-int list_dlibs(ClientData clientData , Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){
+int list_dlibs(ClientData clientData __attribute__((unused)) , Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){
const char *path;
- interp2 = interp;
+ int fd;
+ struct stat stbuf;
+ void * data;
+ Tcl_Obj * libs;
+ macho_input_t input_file;
+
+
if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "directory");
return TCL_ERROR;
@@ -334,38 +349,49 @@
path = Tcl_GetString(objv[1]);
- int fd = open(path, O_RDONLY);
+ fd = open(path, O_RDONLY);
if (fd < 0) {
return TCL_ERROR;
}
- struct stat stbuf;
if (fstat(fd, &stbuf) != 0) {
return TCL_ERROR;
}
/* mmap */
- void *data = mmap(NULL, stbuf.st_size, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0);
- if (data == MAP_FAILED)
- return TCL_ERROR;
+ data = mmap(NULL, stbuf.st_size, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0);
+ if (data != MAP_FAILED){
+ /* Parse */
+ input_file.data = data;
+ input_file.length = stbuf.st_size;
- /* Parse */
- macho_input_t input_file;
- input_file.data = data;
- input_file.length = stbuf.st_size;
+ libs = list_macho_dlibs(&input_file, interp);
- Tcl_Obj * libs = list_macho_dlibs(&input_file);
+ munmap(data, stbuf.st_size);
+ }
+ else{
+ libs = (Tcl_Obj *)TCL_ERROR;
+ }
+ close(fd);
- munmap(data, stbuf.st_size);
- close(fd);
- Tcl_SetObjResult(interp, libs);
+
+ if(libs == (Tcl_Obj *)TCL_ERROR){
+ Tcl_SetObjResult(interp, Tcl_NewListObj(0,NULL));
+ }
+ else{
+ Tcl_SetObjResult(interp, libs);
+ }
return TCL_OK;
}
-int list_archs(ClientData clientData , Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){
- interp2 = interp;
+int list_archs(ClientData clientData __attribute__((unused)), Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]){
const char *path;
+ int fd;
+ struct stat stbuf;
+ void * data;
+ Tcl_Obj * archs;
+ macho_input_t input_file;
if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "directory");
@@ -374,30 +400,34 @@
path = Tcl_GetString(objv[1]);
- int fd = open(path, O_RDONLY);
+ fd = open(path, O_RDONLY);
if (fd < 0) {
return TCL_ERROR;
}
- struct stat stbuf;
if (fstat(fd, &stbuf) != 0) {
return TCL_ERROR;
}
/* mmap */
- void *data = mmap(NULL, stbuf.st_size, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0);
- if (data == MAP_FAILED)
- return TCL_ERROR;
+ data = mmap(NULL, stbuf.st_size, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0);
+ if (data != MAP_FAILED){
+ /* Parse */
+ input_file.data = data;
+ input_file.length = stbuf.st_size;
- /* Parse */
- macho_input_t input_file;
- input_file.data = data;
- input_file.length = stbuf.st_size;
+ archs = list_macho_archs(&input_file, interp);
- Tcl_Obj * archs = list_macho_archs(&input_file);
+ munmap(data, stbuf.st_size);
+ }
+ else{
+ archs = (Tcl_Obj *)TCL_ERROR;
+ }
+ close(fd);
- munmap(data, stbuf.st_size);
- close(fd);
- Tcl_SetObjResult(interp, archs);
+ if(archs == (Tcl_Obj *)TCL_ERROR)
+ Tcl_SetObjResult(interp, Tcl_NewListObj(0,NULL));
+ else
+ Tcl_SetObjResult(interp, archs);
return TCL_OK;
}
Modified: branches/gsoc11-post-destroot/base/src/port1.0/portcheckdestroot.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portcheckdestroot.tcl 2011-07-22 00:16:24 UTC (rev 80962)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portcheckdestroot.tcl 2011-07-22 05:10:06 UTC (rev 80963)
@@ -39,16 +39,6 @@
proc portcheckdestroot::get_port_files {portname} {
}
-# Check if a file is binary file
-# TODO: Somewhat probabilistic. Must be a better way.
-proc portcheckdestroot::binary? filename {
- set f [open $filename]
- set data [read $f 1024]
- close $f
- expr {[string first \x00 $data]>=0}
-}
-
-
# escape chars in order to be usable as regexp. This function is for internal use.
proc portcheckdestroot::escape_chars {str} {
return [regsub -all {\W} $str {\\&}]
@@ -248,8 +238,8 @@
#Get package files
foreach file [files_list $destroot] {
- if { [binary? "$file"] } {
- foreach file_lib [list_dlibs $file] {
+ foreach file_lib [list_dlibs $file] {
+ if { ! [regexp $file_lib $file] } {
if { [lsearch $dep_files $file_lib] != -1 } {
ui_debug "$file_lib binary dependency is met"
} else {
@@ -276,12 +266,10 @@
proc portcheckdestroot::checkdestroot_arches { archs } {
global destroot
foreach file [files_list $destroot] {
- if { [binary? "$file"] } {
- set file_archs [list_archs $file]
- foreach arch $archs {
- if { [lsearch $file_archs $arch] == -1 } {
- return -code error "$file supports the arch $arch, and should not"
- }
+ set file_archs [list_archs $file]
+ foreach arch $file_archs {
+ if { [lsearch $arch $archs] == -1 } {
+ return -code error "$file supports the arch $arch, and should not"
}
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20110721/958a567b/attachment.html>
More information about the macports-changes
mailing list